note 20717 modified in function.array-push by vrana
| From: | vrana@php.net | Date: | Tue, 17 Aug 2004 14:48:29 +0000 |
| Subject: | note 20717 modified in function.array-push by vrana | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-79834@lists.php.net to get a copy of this message | ||
If you want to use integer keys simply treat it as an 'ordinary' array.
<?php
$user_arr = array();
$user_id = 4;
$user_name = 'John';
$user_arr[$user_id] = $user_name;
$user_id = 346;
$user_name = 'Steve';
$user_arr[$user_id] = $user_name;
$user_id = 652;
$user_name = 'Maria';
$user_arr[$user_id] = $user_name;
?>
All slots in between the three user IDs will not be allocated and sizeof($user_arr) will return 3
and not 653.
--was--
If you want to use integer keys simply treat it as an 'ordinary' array.
$user_arr = array();
$user_id = 4;
$user_name = 'John';
$user_arr[$user_id] = $user_name;
$user_id = 346;
$user_name = 'Steve';
$user_arr[$user_id] = $user_name;
$user_id = 652;
$user_name = 'Maria';
$user_arr[$user_id] = $user_name;
All slots in between the three user IDs will not be allocated and sizeof($user_arr) will return 3
and not 653.
http://php.net/manual/en/function.array-push.php