-3

how to insert a variable within the search array?

something like that

<?php
$imagename = ' forest ';
?>

<?php
$myImageslist = array (
'city.png'
'forest.png'
'fruit.png '
'Color.png'
);

shuffle ($myImagesList);

if (($key = array_search ("$imagename.png" $myImagesList))! == false) {
     array_splice ($myImagesList, $ key, 1);

       ?>

what would be the best way to do this?

Brijal Savaliya
  • 1,073
  • 9
  • 19

1 Answers1

0

Apologies if I misunderstood the question, but it looks like you're asking about how to have the first parameter of array_search() be variable in nature. PHP's string concatenation operator is the dot (.). As such, you should be able to do the following:

[...]

if(($key = array_search($imagename . '.png', $myImagesList)) !== false) {
    array_splice($myImagesList, $key, 1);

[...]
Aetiranos
  • 319
  • 1
  • 6
  • Please set the question as answered. :) – Aetiranos Jul 13 '16 at 02:34
  • @GianMartins If this resolved your issue please be sure to accept it. http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work Looking at your history you have a series of not accepting answers. Please get in the habit of accepting answers. – chris85 Jul 13 '16 at 15:02