php中如何自动知道数组的字段名称?
我只是有一个小问题,我找不到任何答案,因为我不知道如何在谷歌上明确地表达它。
所以我从查询中返回了这个数组:
Array
(
[0] => Array
(
[aad3177ec0cbced7a15fae003bdd0ff3] => Array
(
[rowid] => aad3177ec0cbced7a15fae003bdd0ff3
[id] => 21
[qty] => 1
[price] => 176
[name] => KRUPS YY1305
[image] => utilities/images/products/p2070396dt.jpg
[description] => Menu simplifié pour une convivialité optimale.
[subtotal] => 176
)
)
)
我想获取所有信息 rowid、id、qty ...,通过 foreach 循环将其存储在另一个变量中,而不知道第二个数组的名称:“aad3177ec0cbced7a15fae003bdd0ff3”。我只想在用户注销时从存储在数据库中的购物车中检索文章。
那么我该怎么说:
echo $myArray['0'][theNumberGoesHereAutomatically]['price'];
理想情况下,我的代码看起来像这样:
foreach ($data2 as $cart){
$data = array(
'rowid' => $cart_unserialized[$token]['aad3177ec0cbced7a15fae003bdd0ff3']['rowid'],
'id' => $cart_unserialized[$token]['aad3177ec0cbced7a15fae003bdd0ff3']['id'],
'qty' => $cart_unserialized[$token]['aad3177ec0cbced7a15fae003bdd0ff3']['qty'],
'price' => $cart_unserialized[$token]['aad3177ec0cbced7a15fae003bdd0ff3']['price'],
'name' => $cart_unserialized[$token]['aad3177ec0cbced7a15fae003bdd0ff3']['name'],
'image' => $cart_unserialized[$token]['aad3177ec0cbced7a15fae003bdd0ff3']['image'],
'description'=> $cart_unserialized[$token]['aad3177ec0cbced7a15fae003bdd0ff3']['description'],
);
$this->cart->insert($data2);
$token++;
};
在不知道 aad3177ec0cbced7a15fae003bdd0ff3 的情况下。
有什么想法吗?谢谢 :)
I just have a little question, I can't find any answer since I don't know exactly how to formulate it on Google.
So I have this array returned from a query:
Array
(
[0] => Array
(
[aad3177ec0cbced7a15fae003bdd0ff3] => Array
(
[rowid] => aad3177ec0cbced7a15fae003bdd0ff3
[id] => 21
[qty] => 1
[price] => 176
[name] => KRUPS YY1305
[image] => utilities/images/products/p2070396dt.jpg
[description] => Menu simplifié pour une convivialité optimale.
[subtotal] => 176
)
)
)
And I want to get all the information rowid, id, qty ... to store it through a foreach loop in another variable without knowing the name of the second array : 'aad3177ec0cbced7a15fae003bdd0ff3'. I just want to retrieve articles from a cart stored in a database when user logged out.
So how can I say something like :
echo $myArray['0'][theNumberGoesHereAutomatically]['price'];
Ideally, my code would look like that :
foreach ($data2 as $cart){
$data = array(
'rowid' => $cart_unserialized[$token]['aad3177ec0cbced7a15fae003bdd0ff3']['rowid'],
'id' => $cart_unserialized[$token]['aad3177ec0cbced7a15fae003bdd0ff3']['id'],
'qty' => $cart_unserialized[$token]['aad3177ec0cbced7a15fae003bdd0ff3']['qty'],
'price' => $cart_unserialized[$token]['aad3177ec0cbced7a15fae003bdd0ff3']['price'],
'name' => $cart_unserialized[$token]['aad3177ec0cbced7a15fae003bdd0ff3']['name'],
'image' => $cart_unserialized[$token]['aad3177ec0cbced7a15fae003bdd0ff3']['image'],
'description'=> $cart_unserialized[$token]['aad3177ec0cbced7a15fae003bdd0ff3']['description'],
);
$this->cart->insert($data2);
$token++;
};
without knowing the aad3177ec0cbced7a15fae003bdd0ff3.
Any ideas? Thanks :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以通过以下方式轻松完成此操作:
$varname
将包含aad3177ec0cbced7a15fae003bdd0ff3
。You can do this easily with:
$varname
will containaad3177ec0cbced7a15fae003bdd0ff3
.您可以使用
key()
函数获取密钥You can get the key with
key()
function使用
current
函数:Use
current
function: