PHP_Compat
[ class tree: PHP_Compat ] [ index: PHP_Compat ] [ all elements ]

Source for file array_combine.php

Documentation is available at array_combine.php

  1. <?php
  2. // +----------------------------------------------------------------------+
  3. // | PHP Version 4                                                        |
  4. // +----------------------------------------------------------------------+
  5. // | Copyright (c) 1997-2004 The PHP Group                                |
  6. // +----------------------------------------------------------------------+
  7. // | This source file is subject to version 3 of the PHP license,         |
  8. // | that is bundled with this package in the file LICENSE, and is        |
  9. // | available at through the world-wide-web at                           |
  10. // | http://au.php.net/license/3_0.txt.                                   |
  11. // | If you did not receive a copy of the PHP license and are unable to   |
  12. // | obtain it through the world-wide-web, please send a note to          |
  13. // | license@php.net so we can mail you a copy immediately.               |
  14. // +----------------------------------------------------------------------+
  15. // | Author: Aidan Lister <aidan@php.net>                                 |
  16. // +----------------------------------------------------------------------+
  17. //
  18. // $Id: array_combine.php,v 1.10 2004/05/27 09:03:57 aidan Exp $
  19. //
  20.  
  21.  
  22. /**
  23.  * Replace array_combine()
  24.  *
  25.  * PHP 5
  26.  * 
  27.  * http://php.net/function.array_combine
  28.  *
  29.  * @author        Aidan Lister <aidan@virtualexplorer.com.au>
  30.  * @version       1.0
  31.  */
  32. if (!function_exists('array_combine'))
  33. {
  34.     function array_combine(&$keys&$values)
  35.     {
  36.         if (!is_array($keys)) {
  37.             trigger_error('array_combine() expects parameter 1 to be array, string given'E_USER_WARNING);
  38.             return null;
  39.         }
  40.  
  41.         if (!is_array($values)) {
  42.             trigger_error('array_combine() expects parameter 2 to be array, string given'E_USER_WARNING);
  43.             return null;
  44.         }
  45.  
  46.         if (count($keys!== count($values)) {
  47.             trigger_error('array_combine() Both parameters should have equal number of elements'E_USER_WARNING);
  48.             return false;
  49.         }
  50.  
  51.         if (count($keys=== 0 || count($values=== 0{
  52.             trigger_error('array_combine() Both parameters should have number of elements at least 0'E_USER_WARNING);
  53.             return false;
  54.         }
  55.  
  56.         $keys    array_values($keys);
  57.         $values  array_values($values);
  58.  
  59.         $combined = array ();
  60.  
  61.         for ($i = 0$cnt count($values)$i $cnt$i++{
  62.             $combined[$keys[$i]] $values[$i];
  63.         }
  64.  
  65.         return $combined;
  66.     }
  67. }
  68.  
  69. ?>

Documentation generated on Mon, 11 Mar 2019 10:16:56 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.