简体   繁体   English

从 Mysql 数据库中获取数组并以数组形式从用户那里获取数据,如何将数据数组插入到获取的数组中 Php

[英]Getting Array From Mysql database and get data from user in form of array ,how insert data array into fetched Array Php

i'm geting data from user from form and storing that data in $data array, 1st time it insert array in to main array Like [{sub array1} ] 2nd time get new data from user again and fetch data from database and insert new data array into fetched array Data should be upload like [{sub array1},{sub array2}]我从表单中获取用户的数据并将该数据存储在 $data 数组中,第一次将数组插入到主数组中,例如 [{sub array1}]第二次再次从用户那里获取新数据并从数据库中获取数据并插入新的数据数组到获取的数组数据应该像[{sub array1},{sub array2}]一样上传

I don't know if this is what u are asking for but an easy way of storing/getting array from a database is just storing your array as a string separated by a character like "," or ";"我不知道这是否是您所要求的,但是从数据库存储/获取数组的一种简单方法是将数组存储为由“,”“;”等字符分隔的字符串(of course make sure you don't use it in your string) like: (当然要确保你不在你的字符串中使用它)比如:

// 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM