homepage Welcome to WebmasterWorld Guest from 54.197.19.35
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe to WebmasterWorld
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
php problem
shifting a array
ikbenhet1




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

say i have a array:

$lines[0]="info1";
$lines[1]="info2";
$lines[2]="info3";
$lines[3]="info4";

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:

$lines[0]="info1";
$lines[1]="";
$lines[2]="";
$lines[3]="";
$lines[4]="info2";
$lines[5]="info3";
$lines[6]="info4";

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)

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

$startnummer="0";
$ruimte="1";
$teller="10";
while ($teller!=$startnummer)
{
$lines[$startnummer+$teller]=$lines[$startnummer+$teller+$ruimte];
$teller=$teller-"1";
}?>

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.

 

toadhall




msg:1289307
 5:37 am on Nov 12, 2002 (gmt 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.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved