1
    $education = $user->education;

    Array ( [0] => stdClass Object ( [school] => stdClass Object ( [id] => 112629628784911 [name] => Vardhman Shiksha Mandir ) [year] => stdClass Object ( [id] => 136328419721520 [name] => 2009 ) [type] => High School ) [1] => stdClass Object ( [school] => stdClass Object ( [id] => 115934828416686 [name] => jamia hamdrad ) [concentration] => Array ( [0] => stdClass Object ( [id] => 187549374618419 [name] => B.Tech Computer Science ) ) [type] => College ) [2] => stdClass Object ( [school] => stdClass Object ( [id] => 133233016699548 [name] => Hamdard University ) [type] => College [classes] => Array ( [0] => stdClass Object ( [id] => 196267900399898 [name] => 2nd year [with] => Array ( [0] => stdClass Object ( [id] => 553736429 [name] => Ahmed Abdul Zahra ) ) [from] => stdClass Object ( [id] => 553736429 [name] => Ahmed Abdul Zahra ) ) ) ) [3] => stdClass Object ( [school] => stdClass Object ( [id] => 104008189635968 [name] => Jamia Hamdard ) [year] => stdClass Object ( [id] => 138879996141011 [name] => 2013 ) [type] => Graduate School ) ) 

ネストされたforeachループで繰り返してみました。

     foreach($education as $educationFirstArray){
     foreach($educationFirstArray as $educationSecondArray){
        foreach($educationSecondArray as $key=>$value){
         echo "<strong>".$key."</strong> -> ".$value."<br/>";
        }
     }
   }  

出力:

 id -> 112629628784911
 name -> Vardhman Shiksha Mandir
 id -> 136328419721520
 name -> 2009

 Warning: Invalid argument supplied for foreach() in index.php on line 73
  id -> 115934828416686
   name -> jamia hamdrad

 Catchable fatal error: Object of class stdClass could not be converted to string in     index.php on line 74

この配列を上記で繰り返すことに関するヘルプは非常に高く評価されます。よろしくお願いします。

4

1 に答える 1

1

まず第一に、このデータ構造は非常に複雑であると言わなければなりません。混乱した配列またはオブジェクト。ともかく..

単純に、すべてのデータ構造をループする再帰関数が必要だと思います。

function looper($input) {
    foreach ($input as $key => $val) {
        // control here
        if (is_array($val) || is_object($val)) {
            looper($val);
        } else {
            printf("%s -> %s\n", $key, $val);
        }
    }
}

// call
looper($education);

出力;

id-> 112629628784911
名前->VardhmanShiksha Mandir
id-> 136328419721520
名前->2009
タイプ->高校
id-> 115934828416686
名前->ジャミアハムドラッド
id-> 187549374618419
名前->B.TechComputer Science
タイプ->大学
id-> 133233016699548
名前->ハムダード大学
タイプ->大学
id-> 196267900399898
名前->2年目
id-> 553736429
名前->AhmedAbdul Zahra
id-> 553736429
名前->AhmedAbdul Zahra
id-> 104008189635968
名前->ジャミア・ハムダード
id-> 138879996141011
名前->2013
タイプ->大学院

そして、これがあなたのデータ構造のシミュレーションであり、あなた自身から同じプリントを出します。

$education = array(
    (object) array(
        'school' => (object) array('id' => '112629628784911', 'name' => 'Vardhman Shiksha Mandir'),
        'year' => (object) array('id' => '136328419721520', 'name' => '2009'),
        'type' => 'High School'
    ),
    (object) array(
        'school' => (object) array('id' => '115934828416686', 'name' => 'jamia hamdrad'),
        'concentration' => array(
            (object) array('id' => '187549374618419', 'name' => 'B.Tech Computer Science')
        ),
        'type' => 'College'
    ),
    (object) array(
        'school' => (object) array('id' => '133233016699548', 'name' => 'Hamdard University'), 
        'type' => 'College', 
        'classes' => array (
            (object) array('id' => '196267900399898', 'name' => '2nd year', 
                'with' => array((object) array('id' => 553736429, 'name' => 'Ahmed Abdul Zahra')),
                'from' => (object) array('id' => 553736429, 'name' => 'Ahmed Abdul Zahra')
            )
        )
    ),
    (object) array(
        'school' => (object) array('id' => '104008189635968', 'name' => 'Jamia Hamdard'),
        'year' => (object) array('id' => '138879996141011', 'name' => 2013),
        'type' => 'Graduate School'
    ) 
);
于 2013-02-17T15:37:00.590 に答える