English 中文(简体)
在复杂的php 阵列中循环
原标题:Looping through a complex php array
  • 时间:2012-05-25 06:35:10
  •  标签:
  • php
  • arrays
Array (
  [0] => Array ( 
    [event_title] => Registration
    [event_id] => 17
    [location_id] => 113
  )
  [1] => Array (
    [event_title] => Sunday Collections
    [event_id] => 67
    [location_id] => 113
  )
  [2] => Array (
    [event_title] => School Tuition
    [event_id] => 68
    [location_id] => 113
  )
)

谁能告诉我如何从这个阵列中提取 event_标题 , event_id place_id ? 我想以表格的形式实际显示这一点 。

最佳回答

要在表格中显示, 您可以做到这一点 :

<table>
  <tr>
    <th>Event Title</th>
    <th>Event ID</th>
    <th>Location ID</th>
  </tr>
<?php foreach($array as $item): ?>
  <tr>
    <td><?php echo $item[ event_title ] ?></td>
    <td><?php echo $item[ event_id ] ?></td>
    <td><?php echo $item[ location_id ] ?></td>
  </tr>
<?php endforeach; ?>
</table>
问题回答

事实上,数组非常简单 < / 强 > 。

foreach($array as $item) {

    $event_title = $item[ event_title ];
    $event_id = $item[ event_id ];
    $location_id = $item[ location_id ];    

}
<table><?php
    foreach($array as $arr) {
        echo  <tr><td> .
            $arr[ event_title ].
             </td><td> .
            $arr[ event_id ].
             </td><td> .
            $arr[ location_id ].
             </td></tr> .PHP_EOL;
     }
?></table>
foreach ($arr as $event){
    echo $event["event_title"] . "	" . $event["event_id"] . "	". $event["location_id"] . "
";
}
foreach ($array as $row) {
  ...
  echo "<td>{$row[ event_title ]}</td>";
  ...
}




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签