This code works fine but at present i have to change the color value in the “in_array” code manually for each color.
so i thought of creating a function which will automatic check for color value existance and then will echo “checked”.
but i am stuck in this below function
$chosencolors=array("red","yellow");
foreach($chosencolors as $colr)
{
$cl = $colr ." "; // output as red,yellow
$clr = explode(" ",$cl);
echo $clr; // output as ArrayArray
echo $clr[0]; // output as redyellow
}
why is $clr giving output as ArrayArray. Its not splitting with explode.
$chosencolors=array("red","yellow");
foreach($chosencolors as $colr) //Start loop. Get first element of array (red), store it in $colr.
{
$cl = $colr ." ";
echo $cl; // First time through this will echo "red ", second time through it will echo "yellow "
} //Go back to top of loop, use next value of array for $colr. If there are no more elements in the array, exit loop.