Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

php problem

shifting a array

2:32 am on Nov 12, 2002 (gmt 0)

Preferred Member

10+ Year Member

joined:Aug 18, 2002
votes: 0

say i have a array:


And i need to insert 3 (*) empty arrays on location $lines[1] (**) and everything under $lines[1] (**) it must also shift 3 (*) arrays down.

So the result would be:


Is there a PHP command for this?

i couldn't find one that does exactly this. And i got a really weird error message with all weird characters, when i tried to make my own code to do this, and run it on the server.

The code i come up with was:(please don't laugh, i'm new to php, so my code is probably bad)

$filename = 'bestand.txt';
$lines = file($filename);

while ($teller!=$startnummer)

But i got this really weird message.

Can anybody help me out?

(*) i need 3 lines and sometimes just 1 line.
(**) $lines[1] is just an example, it could also be $lines[100] where the 'blank' arrays need to be inserted.

5:37 am on Nov 12, 2002 (gmt 0)

Preferred Member

10+ Year Member

joined:May 9, 2001
votes: 0

You can achieve this using array_slice() [php.net] to split the original array in two, and array_merge() [php.net] to insert a third array containing the blank elements.