invoices
を以下のJSONから分離して配列したいと思っています。PHPのJSON配列オブジェクトからキーベースの値をすべて取得する
[
{
"id":1,
"name":"Demo Name",
"email":"[email protected]",
"mobile":"881730344",
"mobilealt":"78693446777",
"gender":"male",
"address":"102a sdf",
"description":"Super admin role and super admin permissions",
"profileimage":"profileimage\/team1.jpg",
"status":"active",
"created_at":null,
"updated_at":"2016-06-29 17:08:24",
"deleted_at":null,
"under_id":0,
"assign_at":"2016-05-11 10:41:50",
"children":[
{
"id":17,
"under_id":1,
"name":"Some Name",
"children":[
{
"id":35,
"under_id":17,
"name":"test sub user ",
"children":[
],
"invoices":[
]
},
{
"id":36,
"under_id":17,
"name":"Harsh",
"children":[
],
"invoices":[
]
}
],
"invoices":[
]
},
{
"id":18,
"under_id":1,
"name":"Demo Demo Sname",
"children":[
],
"invoices":[
{
"order_id":31,
"sum":161500,
"month":"May",
"user_id":18
}
]
},
{
"id":20,
"under_id":1,
"name":"Divya",
"children":[
],
"invoices":[
]
},
{
"id":25,
"under_id":1,
"name":"Dhiraj",
"children":[
{
"id":19,
"under_id":25,
"name":"New user",
"children":[
{
"id":33,
"under_id":19,
"name":"Demo Sub Sub user",
"children":[
],
"invoices":[
]
}
],
"invoices":[
{
"order_id":32,
"sum":40000,
"month":"July",
"user_id":19
}
]
}
],
"invoices":[
]
}
]
}
]
私は再帰的ループを考えています。しかし、私は以下の方法を試してみましたが、これは動作していないようです。
public function take_invoices($array){
static $arrinvoices = [];
foreach($array as $item){
if(count($item->invoice) > 0){
dd($item->invoice); //------------->Laravel function to die and dump. its always empty
$arrinvoices[] = $item->invoice;
}
if(count($item->children) > 0){
$this->take_invoices($item->children);
}
}
return $arrinvoices;
}
ありがとうございます! (事前に!)
多くの空の ' "請求書は、"'があり、それらは省略すべきか? – RomanPerekhrest
いくつかの請求書があります...どちらが必要ですか? –
はい、空を一度スキップしようとしています。 – user3201500