answersLogoWhite

0

There's several ways:

1) You can put square brackets on the end of a variable to create an array key inside that variable:

$names['first'] = "john"

$names['last'] = "smith"

2) You can use the array function:

$names = array('first' => "john", 'last => "smith");

a lot of people set this function out like this:

$names = array(

'first' => "john",

'last' => "smith"

);

it makes it easier to read

hope this helps

User Avatar

Wiki User

14y ago

What else can I help you with?

Related Questions

How do you empty an array in PHP?

To empty an array in PHP you need to use the unset function like shown below: <?php $array = array('hello', 'hi', 'weee'); unset($array); // empty ?>


What is an insert query in PHP and MySQL?

In a database table, the INSERT INTO statement is used to insert new rows. Let's create a SQL query with acceptable values using the INSERT INTO statement, and then run it by passing it to the PHP mysqli query() function to insert data into the table. To learn more about data science please visit- Learnbay.co


How can i Have php post to self with mysql?

Mysql is an Database where Data from HTML forms will be inserted to it by some scripts like ASP 3 (classic), ASP.NET, PHP, ColdFusion and... What you need is a form (By HTML), an Database and table in Mysql and PHP to insert data from your form to the table. mysql insert command is: INSERT INTO table_name_here (column1, column2, ..) VALUES (value_of_column_1, value_of_column_2, ...)


Php code to insert value from textbox into dropdownlist?

Once you submit a form you can use the $_POST[] array to grab the data from a form with PHP. You can then use this data to insert it into a form. Here is an example: <?php if($_POST['submit']){ $text_box_contents = $_POST['comments']; echo ' <select> <option>'.$text_box_contents .'</option> </select>'; }else{ echo ' <form method="post" action="$_SERVER['self']"> <textarea name="comments" cols="40" rows="5"> hostmysite.com Enter your comments here... </textarea><br> <input type="submit" value="Submit" /> </form>'; } ?>


How do you find the size of an array in PHP?

To find the size of an array in PHP you can either use the count() function or the sizeof() function as they will produce the same result. <?php $array = array(1, 2, 3, 4, 5, 6, 7); echo count($array); // outputs 7 echo sizeof($array); // outputs 7 ?>


How can you mix up the order of values in a PHP array?

To shuffle an array in PHP is easy to do, all you need to use is the shuffle() function like shown below: <?php $array = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); shuffle($array); // array results will be randomly shuffled ?>


How do you insert data in cake php?

In the controller file add some code. For eg. ItemsController.php will have the following code <?php public function add() { if(!empty($this->data)) { $this->Item->set($this->data); if($this->Item->validates($this->data)) { if($this->Item->save($this->data)) { $this->Session->setFlash("<strong>Item added.</strong>"); $this->redirect(array('action' => 'view')); // put your 'yourfile.ctp' in place of 'view' } } } ?> This should send the data object to model file named Item.php which would later save the data to database. For more information visit the blog tutorial of cakephp


How do you pick a random value from a PHP array?

To pick random results from an array in PHP you will need to use the array_rand() function, you can select the amount of results you wish it too select too. <?php $array = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); $rand_results = array_rand($array, 3); // will select 3 random results from the array and store in a new array ?>


How do you copy php files to a CD?

Create Data CD with any available CD burning software and insert the files. Burn.


Program to insert an element in array at beginning?

Answer: Use the unshift() Method You can use the unshift() method to easily add new elements or values at the beginning of an array in JavaScript. This method is a counterpart of the push() method, which adds the elements at the end of an array. However, both method returns the new length of the array To learn more about data science please visit- Learnbay.co


How do you reverse the results in a PHP array?

To reverse the results in a PHP array is really simple, all you need to do is use the array_reverse() function like shown below: <?php $my_array = array(1, 2, 3); $reverse_me = array_reverse($my_array); // will be stored as 3, 2, 1 now ?>


How can you create an array of numbers easily in php?

$foo = array(1.41421356, 1.61803399, 2.71828183, 3.14159265);