-1
我需要使用unserialize php函數獲取產品ID。我有這樣的文字PHP反序列化函數從0-9獲取任意數字
a:1:{i:4;a:17:{s:8:"quantity";i:1;s:10:"product_id";i:5196;s:11:"category_id";s:3:"209";s:5:"price";d:1;s:3:"tax";s:5:"18.00";s:6:"tax_id";s:1:"1";s:11:"description";s:0:"";s:12:"product_name";s:4:"test";s:11:"thumb_image";s:0:"";s:3:"ean";s:0:"";s:10:"attributes";s:6:"a:0:{}";s:16:"attributes_value";a:0:{}s:6:"weight";s:6:"0.0000";s:9:"vendor_id";s:1:"0";s:5:"files";s:6:"a:0:{}";s:14:"freeattributes";s:6:"a:0:{}";s:25:"dependent_attr_serrialize";s:6:"a:0:{}";}}
,我得到這個PHP代碼的product_id:
$rslt = unserialize($data);
echo $rslt[4]["product_id"]);
所以我的問題是有沒有辦法做這樣的事情echo $rslt[x]["product_id"];
其中x是0-9
也試過,但一旦你反序列化不起作用
$i=0;
while($rslt[$i]["product_id"]!="")
{
echo $i;
//echo $rslt[4]["product_id"];
echo $rslt[$i]["product_id"];
$i++;
}
出了什麼問題,你做了什麼? –
@ExplosionPills沒有什麼不對,但$ rslt中的數字[4] - 括號內的數字是{i後的文本中的數字,即4,但不總是4.它可以是0之間的任何數字-9 – Chris
嘗試'echo $ rslt [mt_rand(0,9)] [「product_id」];' – Baba