Jump to content

arrays, objects and sessions!?? help!


thomjjames

Recommended Posts

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!!!

thanks
Tom
Link to comment
Share on other sites

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]
Link to comment
Share on other sites

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 again

Tom
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.