-2

I have an array of arrays formatted like the following:

$list = [ ["fdsa","1","fdsa"],["sadf","0","asdf"],["frfrf","0","sadfdsf"] ]

How can I loop through every single value?

1

2 Answers 2

3

With a RecursiveIteratorIterator?

foreach(new RecursiveIteratorIterator(new RecursiveArrayIterator($list)) as $item){
        var_dump($item);
}

string(4) "fdsa"
string(1) "1"
string(4) "fdsa"
string(4) "sadf"
string(1) "0"
string(4) "asdf"
string(5) "frfrf"
string(1) "0"
string(7) "sadfdsf"

... unless you want it more structured...

Sign up to request clarification or add additional context in comments.

Comments

-2

Try:

$array = array(array("!","Hello","World"));
foreach($array as $key){
    $myvar = $key[0];
    $myvar2 = $key[1];
    $myvar3 = $key[2];
}

UPDATED!

Hope it helped!

1 Comment

And what do you do if there's an array in an array in an array? Add another loop? Or will you then start looking at recursive functions?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.