note 30609 modified in function.array-pad by vrana

From: Date: Tue, 17 Aug 2004 14:47:59 +0000
Subject: note 30609 modified in function.array-pad by vrana
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-79854@lists.php.net to get a copy of this message
To daarius - you mean you have... [2]=>"two" [3]=>"three" and you want... [0]=>"FILLED" [1]=>"FILLED" [2]=>"two" [3]=>"three" [4]=>"FILLED" [5]=>"FILLED" If so, then the following code... <?php $array = array(2 => "two", 3 => "three"); $array = array_pad($array, count($array)+2, "FILLED"); $num = -(count($array)+2); $array = array_pad($array, $num, "FILLED"); print_r($array); ?> will return: Array ( [0] => FILLED [1] => FILLED [2] => two [3] => three [4] => FILLED [5] => FILLED ) The ordering should be okay,... --was-- To daarius - you mean you have... [2]=>"two" [3]=>"three" and you want... [0]=>"FILLED" [1]=>"FILLED" [2]=>"two" [3]=>"three" [4]=>"FILLED" [5]=>"FILLED" If so, then the following code... $array = array(2 => "two", 3 => "three"); $array = array_pad($array, count($array)+2, "FILLED"); $num = -(count($array)+2); $array = array_pad($array, $num, "FILLED"); print_r($array); will return: Array ( [0] => FILLED [1] => FILLED [2] => two [3] => three [4] => FILLED [5] => FILLED ) The ordering should be okay,... http://php.net/manual/en/function.array-pad.php

« previous php.notes (#79854) next »