从嵌套数组输出项目

时间:2014-02-09 02:25:52

标签: php arrays

内部数组中的所有项目是否更简单?

$user = array(
     'name' => 'Joe Blogs',
     'age'  => 25,
     'validate' => 'true',
     'children' => array(
          'Jack',
          'Jill',
          'Mark')
);

echo "The user's details are: " . $user['children'][0] .' '. $user['children'][1] .' and '.   $user['children'][2];

1 个答案:

答案 0 :(得分:1)

利用implode()

<?php
$user = array(
    'name' => 'Joe Blogs',
    'age'  => 25,
    'validate' => 'true',
    'children' => array(
        'Jack',
        'Jill',
        'Mark')
);

echo "The user details are ".implode(',',$user['children']);

<强> OUTPUT :

The user details are Jack,Jill,Mark