A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: array troubles in php

  1. #1
    Member
    Join Date
    Dec 2002
    Posts
    39

    array troubles in php

    Hello all,

    I am searching through a directory and returning the contents to an array($tempArr) and then stripping the extension from the files. From there I am trying to pass a string($tempStr) as the contents of a second array($myArr). I understand why $tempStr isn't actually acting as the contents of $myArr, being it's just a string from the previous statement. I am just not sure on how to fix it. Any suggestions would be appreciated.
    Thanks Joey

    PHP Code:
    $tempstr=join(",",$tempArr);
    $tempstr=str_replace(".png","",$tempstr);

    // I was thinking turn it back into an array and skip to the next function, but this isn't working very well.
    $tempArr=explode("",$tempstr); 

    // works fine, but doesn't self populate.
    $myArr=array(1039,1039,1056,1056,1182);

    //Doesn't work. Returns $tempstr as one element rather than five. This would be the ideal way.
    $myArr=array($tempstr); 

    foreach (
    $myArr as $i) {
    echo 
    "$i<br>";

    Last edited by sillyrabbit; 02-14-2003 at 04:14 PM.

  2. #2
    Okay. Could you just do this.
    $myArr[0]=$tempStr;
    $myArr[1]=$tempStr;

    This way it would add the values of $tempStr to an enumerated array (PHP will automagically create this array for ya). If you are pulling different data into tempStr, then storring it into the array (alla pulling multiple rows out of MySQL DB), you could just run this in a loop replacing $myArr[NUMBER], with $myArr[$SOMEVAR] then increase $SOMEVAR by one each interation of the loop.
    John Starkey: So what if I have had sexual relations with Saddam.

    Looking for a webhost, paid, free, or dedicated? Check out this thread, to get my reviews.

  3. #3
    Originally posted by onlinegs.com
    Okay. Could you just do this.
    $myArr[0]=$tempStr;
    $myArr[1]=$tempStr;

    This way it would add the values of $tempStr to an enumerated array (PHP will automagically create this array for ya). If you are pulling different data into tempStr, then storring it into the array (alla pulling multiple rows out of MySQL DB), you could just run this in a loop replacing $myArr[NUMBER], with $myArr[$SOMEVAR] then increase $SOMEVAR by one each interation of the loop.
    Edit: if this did not help you, feel free to e-mail me at webmaster AT onlinegs DOT com (obviously changing the AT ot @ and the DOT to .).
    John Starkey: So what if I have had sexual relations with Saddam.

    Looking for a webhost, paid, free, or dedicated? Check out this thread, to get my reviews.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center