useCase
useCase

Reputation: 1275

How to find the value from this array in php?

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

Answers (3)

Brad Christie
Brad Christie

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.

demo

Upvotes: 1

KJYe.Name
KJYe.Name

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

Wesley van Opdorp
Wesley van Opdorp

Reputation: 14941

foreach ($aArray as $aValues) {
    echo "type: ".implode(", ", $aValues);
    echo "<br>"; // Or alternative linebreak.
}

Upvotes: 1

Related Questions