新聞中心
新手再請教PHP刪除數(shù)據(jù)庫里的數(shù)組問題!
兄弟這個JSON也學了幾個星期了哦,怎么老是問類似的問題~
創(chuàng)新互聯(lián)從2013年成立,是專業(yè)互聯(lián)網(wǎng)技術服務公司,擁有項目成都網(wǎng)站制作、成都做網(wǎng)站、外貿(mào)營銷網(wǎng)站建設網(wǎng)站策劃,項目實施與項目整合能力。我們以讓每一個夢想脫穎而出為使命,1280元陵川做網(wǎng)站,已為上家服務,為陵川各地企業(yè)和個人服務,聯(lián)系電話:18982081108
?php
$str='{"1":{"11":{"status":0,"time":0},"22":{"status":1,"time":2},"33":{"status":0,"time":1}},"2":{"111":{"status":1,"time":0},"222":{"status":0,"time":1},"333":{"status":0,"time":1}},"3":{"1111":{"status":1,"time":0},"2222":{"status":0,"time":1},"3333":{"status":0,"time":1}}}';
$obj=json_decode($str,true);
foreach ($obj as $key = $value ){
foreach ($value as $key1 = $value1 ){
if ($value1['time'] == 1) unset($obj[$key][$key1]);
}
}
$str=json_encode($obj);
echo $str;
?
PHP怎么刪除整個數(shù)組?
舉例如下:
$a=array(1,2,3);
unset($a);
就可以把整個數(shù)組刪除。
刪除數(shù)組和清空數(shù)組不是一個概念,刪除數(shù)組之后,就是無法訪問了,向上面的例子,我們unset之后, 數(shù)組就不存在了,整個$a都無法訪問了。
PHP刪除數(shù)組中指定的值
?php
//這是在數(shù)據(jù)庫取出的01數(shù)據(jù)
$string?=?"7,12,541";
//把01的數(shù)據(jù)轉為數(shù)組
$string_to_array?=?explode(",",?$string);
//轉換數(shù)組,默認數(shù)組的鍵值對是類似這樣
//array(0=7,1=12,2=541);
//轉換后是array(7=0,12=1,541=2);
$arr_flip?=?array_flip($string_to_array);
//刪除為7的
$delete_mark?=?7;
unset($arr_flip[$delete_mark]);
//數(shù)組再轉回來
$string_to_array?=?array_flip($arr_flip);
//數(shù)組合成字符串
$string_end?=?implode(",",?$string_to_array);
var_dump($string_end);
上面代碼和注釋都寫好了,主要是這部分處理,取出數(shù)據(jù)應該不難吧
分享標題:php刪除數(shù)組數(shù)據(jù)庫 php數(shù)組刪除指定的value
文章轉載:http://fisionsoft.com.cn/article/ddjsoes.html