0

So basically I have this array stored in SQL and I'm trying to retrieve the first element from it using PHP

I'm not sure if this is an associative or multidimensional array

a:3:{i:0;s:11:"Downpayment";i:1;s:28:"Variable 1 ";i:2;s:28:"Variable 2";}

How do I extract elements from this array ?

4
  • are you sure it is the exact data stored in database as its not even proper json Commented Sep 24, 2017 at 21:28
  • 1
    s:28 looks wrong for Variable 1 and Variable 2... they're neither of them 28 bytes in length Commented Sep 24, 2017 at 21:33
  • 1
    @MoeenBasra the string is a serialized array, not a JSON, check serialize() Commented Sep 24, 2017 at 21:33
  • @MarkBaker is right, the length is wrong, can you post how stored the serialize array in your database ? and the original structure of this ? Commented Sep 24, 2017 at 21:36

2 Answers 2

2

This is a PHP representation of serialized data. Use unserialize() on it.

Sign up to request clarification or add additional context in comments.

1 Comment

This worked , thank you so much , i was able to extract it onto an indexed array using serialize()
0

If you not sure in this array you can use current() function or foreach to get first element of this array

For set inner pointer on first element use reset()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.