Archive for the ‘Arrays’ Category

How to display array as Tree
  1. <?php
  2. $customers
  3. = array(
  4. array('first' => 'Bill', 'last' => 'Jones',
  5. 'age' => 24, 'state' => 'CA'),
  6. array('first' => 'Mary', 'last' => 'Smith',
  7. 'age' => 32, 'state' => 'OH'),
  8. array('first' => 'Joyce', 'last' => 'Johnson',
  9. 'age' => 21, 'state' => 'TX'),
  10. );
  11. printf("print_r():<pre>%s</ pre>", print_r($customers, TRUE));
  12. printf("var_export():<pre>%s</ pre>", var_export($customers, TRUE));
  13. print 'var_dump():<pre>';
  14. var_dump($customers);
  15. print '</ pre>';
  16. ?>

,

No Comments


How to Remove Item in Array in PHP

Use unset() to remove an item/element in Arrays, see example below

  1. <?PHP
  2.  
  3. $array = array('name'=>'Bill', 'age'=>32, 1=>'25 Main St.',
  4. 2=>'Apt. 24', 'City'=>'San Francisco', 'state'=>'CA');
  5.  
  6. printf("<pre>;%s</ pre>\n", var_export($array, TRUE));
  7.  
  8. unset($array['age']);
  9.  
  10. printf("<pre>%s</ pre>\n", var_export($array, TRUE));
  11.  
  12. ?>

, ,

No Comments



SetPageWidth