[英]Getting Array From Mysql database and get data from user in form of array ,how insert data array into fetched Array Php
我從表單中獲取用戶的數據並將該數據存儲在 $data 數組中,第一次將數組插入到主數組中,例如 [{sub array1}]第二次再次從用戶那里獲取新數據並從數據庫中獲取數據並插入新的數據數組到獲取的數組數據應該像[{sub array1},{sub array2}]一樣上傳
我不知道這是否是您所要求的,但是從數據庫存儲/獲取數組的一種簡單方法是將數組存儲為由“,”或“;”等字符分隔的字符串 (當然要確保你不在你的字符串中使用它)比如:
// code to upload array as string
$array = array("1","2","3");
$arraytostring = '';
$arraycounter = 1; // counter for check the last element
foreach($array as $element){
$arraytostring .= $element;
if($arraycounter != count($array)){ // don't print the char if this is the last
$arraytostring .= ",";
}
}
// now $arraytostring is your array as a text then you can upload with your db script
// the code to easily retrieve the array
$array = explode(',',$row['column']);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.