Different between two types of array

Array define types
     Type A)
           $arr[] = "value1";
           $arr[] = "value2";
     Type B)
           $arr = array("value1","value2");

Given up the two types of defining array. When you will define 'A' type array and you will use sort(); function to arrange values by ascending order then only values will be arranged by ascending order not keys. But if you apply sort(); function in 'B' type array you will see that not only array but also keys are being arranged by ascending order by sort(); function. And like that rsort(); function will do the same job. rsort(); function will just arrange by descending order.

So if you want to arrange keys or index by ascending order in Type 'A' you have to use the ksort(); function for ascending order and krsort(); function for descending order. But if you use these function on Type 'B' you will see that values and keys are arranging by ascending order or descending order together according to your function ksort(); and krsort();

Comments

Popular posts from this blog

WP register_post_type() with custom CMB2 meta box

Git post receive setup at server for git push to the production from local machine