views:

22

answers:

1

Hello my fellow programmers,

I have a problem (other than not knowing enough) I need to know how to pass an array from outside the scope to then back inside, in a function which then echo's a specific array index.

I have trowlled through the net trying to find solutions, asked fellow programmers for help but nothing thus far has worked.

inside an include file I am creating the array:

$errmsg[0] = 'the message is too short, please enter more than 10 charaters.';
$errmsg[1] = 'the message is too long, please enter less than 1000 charaters.';

I then go on to serialize the array to keep it stored.

$e = serialize($errmsg);

Then inside another include file I create my function.

function contact($e) {
    echo unserialize($errmsg[0]);
}

Lastly in the main index.php file I callback the function.

contact($e);

Now this of course does not work and if any kind soul could put me on the right track or even give me the solution to fixing this I would be greatly appriciative.

If you need any further information from me please say.

p.s. I have now finished work for the day so my responses wont be until later tonight GMT.

+1  A: 
function contact() {
    global $e;
    $unserialize =  unserialize($e);
    echo $unserialize[0];
}

contact();

Better would be:

$errmsg[0] = '...'; $errmsg[1] = '...';

$e = serialize($errmsg);

function concact($e) {
    $array = unserialize($e);
    echo $array[0];
}

// now maybe: contact($e);
ahmet2106
Worked a charm, :) cant believe all I was missing was calling back the serialized array as an normal array and then echo'ing it back. Thank you very much for your help.
Daniel Wrigley