$image = I('image');//獲取多圖上傳路徑
$img_id = array();//定義空數(shù)組
foreach ($image as $k=>&$v){ //循環(huán)多圖數(shù)據(jù)
$data = array( //定義添加數(shù)據(jù)
'url'=>$v,
'add_time'=>time()
);
$img = M('contract_img')->add($data);//添加操作
$img_id[]['imgid'] = $img; //保存添加后數(shù)據(jù)id
}
dump($img_id);
打印出來是這樣的:
image.png
接下來就是轉(zhuǎn)換數(shù)據(jù)了
$a = array_column($img_id,'imgid');//以數(shù)組中某個相同的字段進(jìn)行組合 詳細(xì)解說:http://www.lxweimin.com/p/43e987a0de6a
$arr = implode(',',array_column($img_id,'imgid'));//以,間隔方式 組合字符串
dump($arr);
數(shù)據(jù)轉(zhuǎn)換完成
PS:
//利用 explode 函數(shù)分割字符串到數(shù)組
<?php
$source = "hello1,hello2,hello3,hello4,hello5";//按逗號分離字符串
$hello = explode(',',$source);
for($index=0;$index<count($hello);$index++)
{
echo $hello[$index];echo "</br>";
}
?>
implode 函數(shù):將數(shù)組元素組合為字符串
<?php
$array = array('姓名', '電話', '電子郵箱');
$char = implode(",", $array);
echo $char;
?>