Forum Moderators: coopster

Message Too Old, No Replies

modify array

         

ayushchd

4:01 pm on Oct 7, 2007 (gmt 0)

10+ Year Member



Hi, i have an array.

What I want is that if that array has less than 5 elements, then it should add the number of elements required to make it 5, and the value of those elements should be 0.

Please help me.

eelixduppy

4:09 pm on Oct 7, 2007 (gmt 0)




$arr = array(1,2);
$arr = [url=http://www.php.net/array-pad]array_pad[/url]($arr, 5, 0);
echo '<pre>';
print_r($arr);
echo '</pre>';

Should do it :)

ayushchd

4:34 pm on Oct 7, 2007 (gmt 0)

10+ Year Member



Thanks.

Is it possible to determine if a particular word exists in a string?
I have this :

$start_indicate = 'Capital';

I want that if the word 'Capital' does not exist, $start_indicate to become Liabilities

dreamcatcher

5:46 pm on Oct 7, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



if (strpos [uk.php.net]($start_indicate,'Capital')===FALSE) {
$start_indicate = 'Liabilities';
}

dc

ayushchd

5:55 pm on Oct 7, 2007 (gmt 0)

10+ Year Member



Thanks dc.

I saw it on php.net after posting ;)