answersLogoWhite

0

Creating an array command in PHP will allow an array to return the parameters you have listed for it. Following the steps below will help you use the array command in PHP.

  • The first step is understanding the syntax used. When you see brackets, it indicates an optional part of the syntax. Whereas the ellipsis “…” indicates that the pattern may be continued as needed. The trailing comma in the syntax is optional, but it is a valid part of the syntax as well.The following is an example of a simple array:

$myArray = array(“red”, “blue”, “green”);?>

  • You must also understand how the indexes are generated as well. A 0 will be used to indicate the first index, and each index that follows will be indicated by increasing the previous number by one, unless otherwise specified. When creating an array command, you are able to use either strings or numbers for all the indexes and values. Below is an example of how to specify the indexes:

$myArray = array(3=>”red”, 2=>”blue”, 1=>”green”);?>

  • Finally, you will want to understand how to initialize an array as well. Below is an example where the array created is called myArray. myArray will have the value “red” at index 3, the value “blue at index 4 and the value “green” at index 5. Take a look at how the index is initialized to 3 and the subsequent indexes are increased by one.

$myArray = array(3=>”red”, “blue”, “green”);?>

Once you have a basic understanding of each step of the array and what each aspect of the array is used for, you can be successful in using the array command in PHP. After you have read the step above, you should be ready to use the array command successfully.

User Avatar

Wiki User

15y 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 ?>


How do you separate word in array using php?

To separate a sentence into an array of words, you can use PHP's explode() function. If $text is your sentence, then use the following: $result = explode(" ", $text);


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 find the PHP version in Linux?

In terminal use the following command. php -ver


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 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 check if a value is already in an array in PHP?

To check if a value is already in an array you will need to use the in_array function like shown below! <?php $values = array("pizza","hello","cheese","fred"); $newvalue = "hello"; if (in_array($newvalue, $values)) { echo "$newvalue is already in the array!"; } ?>


How do you flip an array without using flip function in PHP?

Use a for-loop starting at the length of the array and go backwards and build up a new array with the values.


How do you get a looped array from Flash into PHP?

If you're going from flash to PHP then I would use the Get variables and use a pipe character | (%7C HTML char code) to delimit the array. mysite.com?myvar=8|15|22|88 or mysite.com?myvar=8%7C15%7C22%7C88 If you're going from PHP to flash then use XML. Hope that helps


What is the Use of a dollar sign in php?

the dollar sign appears before a variable/array. Essentially it just tells php that its a variable. $food = "cheese pizza"; or $myfavoritenumber = 2 ;


How do you sort variable in ascending or descending order both in php?

Assuming that the values are stored in an array, you can use the php function sort($array) to sort ascending, and rsort to sort descending. The following link gives a table that lists all of the built in PHP sort functions: http://php.net/manual/en/array.sorting.php