![](/img/trans.png)
[英]How to get the value of specific index inside an array column using mysql?
[英]How to get array index number by specific value
我有一個數組
它是一個json數據。
"score":[
{
"userId":"5",
"playtime":"1396369254",
"score":"25"
},
{
"userId":"3",
"playtime":"1396369246",
"score":"2"
},
{
"userId":"1",
"playtime":"1396369056",
"score":"12"
},
{
"userId":"2",
"playtime":"1396369240",
"score":"100"
}
],
我想打印 userId 值為 1 的數組索引號。
像這樣使用 foreach:
foreach($array as $key=>$value) {
if($value['userId'] == 1) {
print $key;
break;
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.