how to access individual items in a POST array?

I have an array like this $perfs = $_POST['perfs'], which a couple of numbers.


I would like to be able to access the items by index, like one would in javascript for example:

$diff = $perfs[1] - $perfs[0];

but that results in: $diff => 2

What I'm looking for is: $diff => 262

when I echo $perfs[1], I get 3 not 1344799479334
when I echo $perfs[0], I get 1 not 1344799479072

How can I access my original values?
LVL 25
Kyle HamiltonData ScientistAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

You need to either explode that string on the comma or str_split to be able to access that like u want
Dave BaldwinFixer of ProblemsCommented:
I t looks like the original data is just a string.  So like Steve said, you need to 'explode' the two parts into an array.

$perfs = explode(",", $_POST['perfs']);
echo $perfs[0];
echo $perfs[1];
echo $perfs[1] - $perfs[0];

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Kyle HamiltonData ScientistAuthor Commented:
That works. thanks guys.
JavaScript Best Practices

Save hours in development time and avoid common mistakes by learning the best practices to use for JavaScript.

Dave BaldwinFixer of ProblemsCommented:
You're welcome.
Kyle HamiltonData ScientistAuthor Commented:
Just curious, why do they call it an array?

I can see now how in my instance it really was a string (which I was passing via ajax):

var data = ['perfs='+navigationStart, domLoading];

But even when I've submitted forms, I would have to retrieve each input individually, for example: $email = $_POST['email'] and $name = $_POST["name']

So when is it actually an array?
Dave BaldwinFixer of ProblemsCommented:
$_POST is the array, 'email' and 'name' are the keys.  Details here:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.