简体   繁体   中英

How to loop inside of array in php

I want to loop data inside of array, without loop array, anyone can help me with this problem? this is my code..

<?php
$arrUtil = array();
while($dtRoomsUtil = mfa($roomsUtil)){
    $arrUtil[] = array(
        "id" => $dtRoomsUtil['id'],
        "name" => $dtRoomsUtil['name'],
        "label" => $dtRoomsUtil['label'],
        "type" => $dtRoomsUtil['type']
    );
}
while($dtUtils = mysql_fetch_array($quUtils)){
$arrData = array(
 foreach($arrUtil as $value){
  $value['name'] => $dtUtils[$value['name']]
 }
}
);
?>

thats give me error, and i think because a foreach function, anybody know about the other ways to solve this problem?

Thanks for help..

You can't init array in such way. Make it like so:

$arrData = array();
 foreach($arrUtil as $value) {
  $arrData[$value['name']] = $dtUtils[$value['name']];
 }

您可以数据送到数组中,在循环中使用array_push($array,$element)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM