How the Values Are Ordered in an Array?

deepak singh
Posts: 686
Joined: Fri Sep 30, 2016 4:19 pm

How the Values Are Ordered in an Array?

Postby deepak singh » Sat Oct 01, 2016 5:26 pm

How the Values Are Ordered in an Array?

deepak singh
Posts: 686
Joined: Fri Sep 30, 2016 4:19 pm

Re: How the Values Are Ordered in an Array?

Postby deepak singh » Sat Oct 01, 2016 5:26 pm

PHP says that an array is an ordered map. But how the values are ordered in an array? The answer is simple. Values are stored in the same order as they are inserted like a queue. If you want to reorder them differently, you need to use a sort function. Here is a PHP script show you the order of array values:
<?php
$mixed = array();
$mixed["Two"] = "Java";
$mixed["3"] = "C+";
$mixed["Zero"] = "PHP";
$mixed[1] = "Perl";
$mixed[""] = "Basic";
$mixed[] = "Pascal";
$mixed[] = "FORTRAN";
$mixed["Two"] = "";
unset($mixed[4]);
print("Order of array values:\n");
print_r($mixed);
?>
This script will print:
Order of array values:
Array
(
[Two] =>
[3] => C+
[Zero] => PHP
[1] => Perl
[] => Basic
[5] => FORTRAN
)


Return to “PHP”

Who is online

Users browsing this forum: No registered users and 1 guest