Posted By

ashmenon on 09/09/12


Tagged


Versions (?)

Beginner PHP Chapter 5 - Arrays - Code Block 2


 / Published in: PHP
 

Beginner PHP Chapter 5 - Arrays

  1. <?php
  2.  
  3. $variable_name = array(); //Create a blank array, or empties an array.
  4.  
  5. $variable_name[] = 'valueA'; //Add a value to the array. If you do this again, it will add a second value to it, not replace the first one.
  6. array_push($variable_name,'valueB'); //Another way to add a value to an array.
  7.  
  8. echo count($variable_name); //Displays the number of values in the array. This will input 2, because we added valueA and valueB to the array.
  9.  
  10. sort($variable_name); //Sorts the values within an array. There are several types of sorting, each with their own options.
  11.  
  12. ?>

Report this snippet  

You need to login to post a comment.