I know it is easy, but it is really confusing me that where is my error.
I have an array:
<?php
$array=array("prod1=>1; prod2=>2; product=>3");
foreach($array as $prod => $value){
$prod = "Expected value prod1";
$value = "Expected value 1";
}
?>
but it is returing again array..
please help me
<?php
$array=array("prod1"=>1, "prod2"=>2, "product"=>3);
foreach($array as $prod => $value){
echo $prod;
echo ' -> ';
echo $value;
echo '<br>';
}
?>
Output will be :
prod1 -> 1
prod2 -> 2
product -> 3
Your declaration of array was wrong. All the best.!
I. You are missing a closing curly brace.
foreach($a as $b) {
// do stuff
}
II. Your array is wrong. How to create an array:
$new = array(1=>'one', 2=>'two', 3=>'three');
the right way to create an array is like the following :
$array=array('prod1'=>1 , 'prod2' =>2 , 'product'=>3 );