开发者

is there another samples of php foreach?

开发者 https://www.devze.com 2023-02-13 08:42 出处:网络
I looking for another samples of php foreach code that similar to the code as following: foreach ($this->ask-&g开发者_如何学Pythont;post[\'books\'] as $book) {

I looking for another samples of php foreach code that similar to the code as following:

foreach ($this->ask-&g开发者_如何学Pythont;post['books'] as $book) {
    if ($book['qty']) {
        $this->goto->add($book['book_id'], $book['qty'], (isset($book['opt'])) ? $book['opt'] : NULL);
    }
} 

I just want to save it as my collection, so, is there another samples of php foreach that You may know? let me know it. Thanks


Maybe this example can help you:

foreach($myArrayOfObject as $key=>$object) {
    if($object->aPropertyOfMyObject) {
        // do something...
    }
}

You can also have a look to http://php.net/manual/en/control-structures.foreach.php


Do you specifically need foreach?

You can also use this:

<?php

$array = array(); // Imagine a filled array
array $max = count($array);

for($i=0;$i<$max;$i++) {
 // Loop over the array
 echo $array[$i]['name_of_key']; 
}

?>
0

精彩评论

暂无评论...
验证码 换一张
取 消