Jump to content


Photo

arrays, objects and sessions!?? help!


  • Please log in to reply
2 replies to this topic

#1 thomjjames

thomjjames
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 05 March 2006 - 08:18 PM

Hi everyone,

i'm alittle stuck with the array below that is produced by a session variable on my site. It seems to contain objects within the arrays, and this has really thrown me as i'm no great PHPer and i'm just going round in circles!!

What i want to do is look through the array [called 'file_uploads' see below] and remove any arrays it contains that are called 'flexinode_10' or 'flexinode_something'.
Then reconstruct the session variable minus the 'flexinode' arrays.
Hope that makes sense.


Here's an example array ['file_uploads'], the array could contain X amount of arrays, depending on how many files are uploaded.

Array (

//i want to keep this array
[upload_1] => stdClass Object (

[filename] => ar-lgflag.gif
[filemime] => image/gif
[filepath] => /tmp/ar-lgflag.gif
[error] => 0 [filesize] => 7053
[source] => upload_1
[list]=> 1
[_filename] => files/ar-lgflag.gif

)

//i want to remove this array
[flexinode_10] => stdClass Object (

[filename] => brxbxp65530.jpg
[filemime] => image/jpeg
[filepath] => /tmp/brxbxp65530.jpg
[error] => 0
[filesize] => 20187
[source] => flexinode_10
[_filename] => files/brxbxp65530.jpg

)

)




Any help or a push in the right direction would be amazing, as i'm just going on trial and error and getting nowhere!!!

thanks
Tom

#2 Kris

Kris
  • Staff Alumni
  • Advanced Member
  • 2,755 posts
  • LocationThe Internet

Posted 05 March 2006 - 11:06 PM

Not sure if this would work straight off the bat, might need a bit of tweaking on your behalf but this is the general idea that I'm thinking:
<?php
//$old_array contains your current array
$new_array = array();

$keys = array_keys($old_array);
for($i=0; $i<count($keys); $i++) {
    if(strpos($keys[$i],"flexinode_") === FALSE)
        $new_array[] .= $old_array[$i];
}

print_r($new_array); //Should display your array with the flexinode keys removed.
?>


#3 thomjjames

thomjjames
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 06 March 2006 - 12:19 PM

Hi there,

thanks alot for the suggestion i have made progress as a result of it.

it successfully removes the 'flexinode_' array from the main array and i made a slight change to maintain the names of the arrays. see my slightly changed version below:
//$old_array contains your current array
$new_array = array();
$keys = array_keys($old_array);


$keys = array_keys($old_array);
for($i=0; $i<count($keys); $i++) {
    echo "<br />". $keys[$i];
    
    if(strpos($keys[$i],"flexinode_") === FALSE)
        $new_array[$keys[$i]] .= $old_array[$keys[$i]];
}

print_r($new_array); //Should display your array with the flexinode keys removed.

however, i still have alittle problem with the outputting the remaining arrays in full. At present i'm getting an output of:
Array ( [upload_1] => Object [upload_2] => Object [upload_3] => Object [upload_4] => Object [upload_5] => Object [upload_6] => Object [upload_7] => Object )

it seems that $old_array[$i] is not picking up its value from the original array, is this because this because these values are in an object not an array?

how do i go about getting this correct values out of these objects in order to recreate the array??

thanks again

Tom




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users