Jump to content

question: array val -> session -> refresh, echo "something", repeat - foreach


DamienRoche

Recommended Posts

Not sure if I was specific enough up there.

 

Here's what I want to do:

 

I have an array with some values, let's say.....

$arr = array('val1','val2','val3');

 

I want to first save those arrays to a session.....

$_SESSION['arr']= $arr;

 

Then I want to refresh.........

header("location:".basename(__FILE__));

 

Then I want to echo then remove one of the values....

echo $arr[0]." has been processed"; 
$arr = array_diff($arr, $arr[0]);

 

Then I want to repeat until there are no more arrays...

 

I would greatly appreciate any insight into how I can achieve this or if it is even possible. I'd like to put it into a foreach somehow...so the updated array is echoed each time but still redirected...agh, I'm confused.

 

 

 

Link to comment
Share on other sites

Heres the code, the second file used here is calles test.php through which we pass the value and u can retrieve that value using GET method. 

 

<?php session_start();

$arr = array("one","two");
$_SESSION['arr'] = $arr;

//count the number of items in the array;

$tot = count($arr);
$i = 0;
while($i<$tot){

//lets send the array value to the next page for futher manipulation
$url = "test.php?arrVal=".$_SESSION['arr'][$i];
header('Location: '.$url);
    $i++;
    if($i == $tot){
echo "Completed";
exit;	 	
}


?>

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.