Reputation: 1275
i have an Array , How can get the value of this array
Array
(
[0] => Array
(
[0] => raj
[1] => 1234
[2] => gov
)
[1] => Array
(
[0] => some
[1] => 1234
[2] => prv
)
[2] => Array
(
[0] => lal
[1] => 234
[2] => prv
)
)
i want the value like this type: raj, 1234, gov
Upvotes: 1
Views: 110
Reputation: 101604
Short answer:
If your array above was stored in the variable $foo
, getting the first nested array within is as easy as $foo[0]
(second is $foo[1]
. third is $foo[2]
, and so on). Then, to get the values within that, you can reference the nested values within using the same method (the brackets).
$foo = /* that array */
$foo[0] // this is the first array, array([0] => 'raj', [1] => 1234, [2] => 'gov');
$foo[0][0] // this is "raj" (reference element one of the first array)
echo implode(', ',$foo[0])); // use implode and make all element of "$foo[0]"
// display, separated by commas and a space.
Upvotes: 1
Reputation: 17169
for($i=0; $i<count($data); $i++){
echo 'type: ' . $data[$i][0] . ', ' . $data[$i][1] . ', ' . $data[$i][2] . PHP_EOL;
}
This is one way to output it, and the result should be:
type: raj, 1234, gov
type: some, 1234, prv
type: lal, 234, prv
Upvotes: 1
Reputation: 14941
foreach ($aArray as $aValues) {
echo "type: ".implode(", ", $aValues);
echo "<br>"; // Or alternative linebreak.
}
Upvotes: 1