如何解决多维数组中的问题

时间:2017-02-05 10:50:56

标签: php php-5.5

我有一个多维数组,如下所示。我想在循环中显示内容,所以我使用foreach循环,但我收到错误

  

**注意:未定义的索引:C:\ xampp \ htdocs中的propertyId **

我该如何解决这个问题?

$proprty_id=
Array
(
    [propertyId] => Array
        (
            [0] => 1
            [1] => 2
            [2] => 3
            [3] => 4
        )

    [ProprtyName] => Array
        (
            [0] => Residential Project 1 
            [1] => Residential Project 2
            [2] => Residential Property 3
            [3] => Residential Property 4
        )

)
foreach($proprty_id as $property){
    echo "ID = ".$property['propertyId']."<br>";
}

1 个答案:

答案 0 :(得分:0)

您将数组定义为$proprty_id 并将其命名为$property 还有一些拼写错误?

你的循环没有检查你的数组,因为它有不同的名字。

$property=array(
    ['propertyId'] => Array
        (
            [0] => 1
            [1] => 2
            [2] => 3
            [3] => 4
        )

    ['ProprtyName'] => Array
        (
            [0] => Residential Project 1 
            [1] => Residential Project 2
            [2] => Residential Property 3
            [3] => Residential Property 4
        )

)
               foreach($property['propertyId'] as $v){

                    echo "ID = ".$v."<br>";
                }