array_put_to_position

The Responsive Minimal array put to position function.

Description

array_put_to_position( &$array, $object, $position, (constant) $name = null ); 

Parameters (4)

0. $array
The array.
1. $object
The object.
2. $position
The position.
3. $name — Optional. (constant) => null
The name.

Usage

  1. if ( !function_exists( 'array_put_to_position' ) ) { 
  2. require_once '/functions/layout_callback.php'; 
  3.  
  4. // The array. 
  5. $array = &$array; 
  6.  
  7. // The object. 
  8. $object = null; 
  9.  
  10. // The position. 
  11. $position = null; 
  12.  
  13. // The name. 
  14. $name = null; 
  15.  
  16. // NOTICE! Understand what this does before running. 
  17. $result = array_put_to_position($array, $object, $position, $name); 
  18.  

Defined (1)

The function is defined in the following location(s).

/functions/layout_callback.php  
  1. function array_put_to_position(&$array, $object, $position, $name = null) { 
  2. $count = 0; 
  3. $return = array(); 
  4. foreach ($array as $k => $v) 
  5. {  
  6. // insert new object 
  7. if ($count == $position) 
  8. {  
  9. if (!$name) $name = $count; 
  10. $return[$name] = $object; 
  11. $inserted = true; 
  12. }  
  13. // insert old object 
  14. $return[$k] = $v; 
  15. $count++; 
  16. }  
  17. if (!$name) $name = $count; 
  18. if (!$inserted) $return[$name]; 
  19. $array = $return; 
  20. return $array;