thomjjames Posted March 5, 2006 Share Posted March 5, 2006 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.[code]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))[/code]Any help or a push in the right direction would be amazing, as i'm just going on trial and error and getting nowhere!!!thanksTom Quote Link to comment https://forums.phpfreaks.com/topic/4160-arrays-objects-and-sessions-help/ Share on other sites More sharing options...
zq29 Posted March 5, 2006 Share Posted March 5, 2006 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:[code]<?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.?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/4160-arrays-objects-and-sessions-help/#findComment-14482 Share on other sites More sharing options...
thomjjames Posted March 6, 2006 Author Share Posted March 6, 2006 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:[code]//$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.[/code]however, i still have alittle problem with the outputting the remaining arrays in full. At present i'm getting an output of:[code]Array ( [upload_1] => Object [upload_2] => Object [upload_3] => Object [upload_4] => Object [upload_5] => Object [upload_6] => Object [upload_7] => Object )[/code]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 againTom Quote Link to comment https://forums.phpfreaks.com/topic/4160-arrays-objects-and-sessions-help/#findComment-14605 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.