Three-dimensional array insert database related issues

Source: Internet
Author: User
Three-dimensional arrays inserting database problems
$arrData = Array (
' Manager ' = ' 5 ',
' Blogname ' = ' blog ',
' Domain ' = ' bokee ',
' user[1] ' =>array (' uid ' = 1, ' name ' = ' Zhangsan '),
' User[2 ' =>array (' uid ' =>2, ' name ' = ' Lisi '),
);
The ' manager ' in this array, ' blogname ', ' domain ' to be inserted into a table, and user[] to be plugged into another table, user[] may also 3,4,5 ... how do I do this? Thank you.

------Solution--------------------
PHP Code
$arrData = Array (' manager ' = ' 5 ', ' blogname ' = ' blog ', ' domain ' = ' bokee ', ' user[1 ' =>array (' uid ' = ' = 1, ' Name ' = ' = ' Zhangsan '), ' user[2 ' =>array (' uid ' =>2, ' name ' = ' Lisi '); foreach ($arrData as $value) {if (        GetType ($value) = = = ' array ') {echo $value [' uid '];    echo $value [' name ']; }}
------Solution--------------------
Programmers have control over the program.
------Solution--------------------
Landlord, that is a two-dimensional array:
PHP Code
$arrData = Array (' manager ' = ' 5 ', ' blogname ' = ' blog ', ' domain ' = ' bokee ', ' user[1 ' =>array (' uid ' = ' = 1, ' Name ' = ' Zhangsan '), ' user[2 ' =>array (' uid ' =>2, ' name ' = ' Lisi '), #这是二维数组foreach ($arrData as $k =>$    Data) {if (Is_array ($data)) $user [] = $data; else $arr [$k] = $data;}  Print_r ($arr); #Array ([manager] = 5 [blogname] + blog [domain] = bokee) print_r ($user); #Array ([0] = = Array ([UID] = 1 [name] = Zhangsan) [1] = = Array ([uid] = 2 [Name] = + Lisi))
------Solution--------------------
This will write 1 methods of insertion and field generation.
Split the 2 arrays first
There may be errors, adjust yourself.
PHP code
 $arrData = Array (' manager ' = ' 5 ', ' blogname ' = ') Blog ', ' domain ' = ' bokee ', ' user[1 ' ' =>array (' uid ' = 1, ' name ' = ' Zhangsan '), ' user[2 ' =>array (' uid ' = 2, ' name ' = ' Lisi '), $data 1 =array (' manager ' = ' 5 ', ' blogname ' = ' blog ', ' domain ' = ' bokee ',); $data 2 = (array $arrData [' User '];//data1 we won't say it. function Add ($data, $table) {foreach ($data as $v) {$key = Implode (",", Array_keys ($v)   ); $key = ". $key. '   `';   $value = Implode ("', '", Array_values ($v));   $value = "'". $value. "'";   if (! $res = Create ($key, $value, $table)) {return $res; }}//Build Result: uid,name}function Create ($key, $value, $table) {INSERT INTO $table ($key) VALUES ($value)} 
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.