Php foreach loop key print a particular value -
i'm trying individual values php foreach loop.
my code
$foo = array('a' => 'apple', 'b' => 'ball', 'c' => 'coke'); foreach($foo $key => $item) { // need display 1 array value key below, // first entry key : // first entry value: apple }
help me ?
$foo = array('a' => 'apple', 'b' => 'ball', 'c' => 'coke'); foreach($foo $key => $item) { echo $key; echo $item; }
will output
a apple b ball c coke
or if want first item only, use
echo $foo['a'];
will output
apple
or first array item without knowing key
$keys = array_keys($foo); $values = array_values($foo); echo $keys[0]; echo $values[0];
Comments
Post a Comment