簡體   English   中英

如何從給定的嵌套數組中獲取元素?

[英]How to fetch the elements from the given nested array?

我從android獲取一個jsonobject並使用json_decode()對其進行解碼后以這種格式獲取它,現在我想將這些數據插入數據庫中。 我該如何獲取這些數據,請幫忙...提前謝謝...

Array
 (
    [0] => Array
        (
            [name] => ramesh
            [empid] => emp32451
        )
    [1] => Array
        (
            [name] => Ranjith
            [empid] => emp89884
        )
)

的PHP:

<?php

header('Content-type: application/json');
$decoded= json_decode($_POST['submit_data']);
json_encode($decoded);
$emplist = $decoded;
print_r ($emplist);
?>

嘗試將其添加到print_r()行要從數組中獲取值的位置。

for ( $i = 0; $i < count( $emplist ); $i++ ) {
  $name = $emplist[$i]["name"];
  $empid = $emplist[$i]["empid"];

  // write to the database in the database's specified manner
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM