note 25317 modified in function.array-pad by vrana

From: Date: Tue, 17 Aug 2004 14:48:01 +0000
Subject: note 25317 modified in function.array-pad by vrana
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-79809@lists.php.net to get a copy of this message
OR you could do this <?php $myArr = array(2 => 'three', 3 => 'four'); $newArr = array_pad(array(), 4, 'FILLED'); $newArr =$myArr+$newArr; ?> This gives your desired result BUT the ordering is a little wierd, because of the order they were added. Indexes are okay though and that is what you wanted. print_r($newArr) outputs Array ( [2] => three [3] => four [0] => FILLED [1] => FILLED ) hope this helps --was-- OR you could do this $myArr = array(2 => 'three', 3 => 'four'); $newArr = array_pad(array(), 4, 'FILLED'); $newArr =$myArr+$newArr; This gives your desired result BUT the ordering is a little wierd, because of the order they were added. Indexes are okay though and that is what you wanted. print_r($newArr) outputs Array ( [2] => three [3] => four [0] => FILLED [1] => FILLED ) hope this helps http://php.net/manual/en/function.array-pad.php

« previous php.notes (#79809) next »