PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, January 29, 2022

[FIXED] How to combine one key with array as value?

 January 29, 2022     codeigniter, php     No comments   

Issue

I have an array and I want to create a table with that array as a column in codeigniter.

How can I combine data that as another array?

Here are my column names

Array
(
    [0] => System_ID
    [1] => Last Name
    [2] => First Name
    [3] => Full Name
    [4] => Phone
    [5] => Ext
    [6] => Email
    [7] => Dept
    [8] => Site
    [9] => Room
    [10] => Job Title
    [11] => Image
    [12] => URL
    [13] => Active
)

And here is the array that I want to combine as value

Array
(
    [type] => VARCHAR
    [constraint] => 200
)

This is the final result I want:

$fields = array(
    'System_ID' => array(
            'type' => 'VARCHAR',
            'constraint' => '100',
    ),
);

Solution

If you want same value for all values from first array, then simple array_fill_keys will work:

$array1 = ['System ID', 'Last Name'];
$array2 = [
    'type' => 'VARCHAR',
    'constraint' => '200',
];
print_r(array_fill_keys($array1, $array2));

Demo.



Answered By - u_mulder
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing