chaseman Posted April 14, 2011 Share Posted April 14, 2011 I have in ONE MySQL database row a string of ID's like this: Name of Row:Values: Post IDs10 14 52 37 And now I want to fetch those ID's explode them (by the space) and then use them as an array, like this: $array[] = explode(" ", $query); echo $array[0]; // 10 echo $array[1]; // 14 echo $array[2]; // 52 Is this possible, if yes how can I do this? Quote Link to comment https://forums.phpfreaks.com/topic/233760-explode-string-and-use-as-array/ Share on other sites More sharing options...
kenrbnsn Posted April 14, 2011 Share Posted April 14, 2011 Actually it's <?php $array = explode(" ", $query); echo $array[0]; // 10 echo $array[1]; // 14 echo $array[2]; // 52 ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/233760-explode-string-and-use-as-array/#findComment-1201777 Share on other sites More sharing options...
gizmola Posted April 14, 2011 Share Posted April 14, 2011 query and fetch the column into a variable. Then use your explode. What is the confusion, you already described exactly what you need to do along with the function you need to do it. Quote Link to comment https://forums.phpfreaks.com/topic/233760-explode-string-and-use-as-array/#findComment-1201778 Share on other sites More sharing options...
chaseman Posted April 14, 2011 Author Share Posted April 14, 2011 Confusion was that I had the brackets around it thinking that would be the correct way, and ken corrected me. Besides that I like posting new threads, and I posted this for the sake of it. The last part was sarcasm, the first part was true. Quote Link to comment https://forums.phpfreaks.com/topic/233760-explode-string-and-use-as-array/#findComment-1201781 Share on other sites More sharing options...
gizmola Posted April 14, 2011 Share Posted April 14, 2011 Confusion was that I had the brackets around it thinking that would be the correct way, and ken corrected me. Besides that I like posting new threads, and I posted this for the sake of it. The last part was sarcasm, the first part was true. You would help everyone out including yourself, if you did a better job describing your problem. Yes you had the wrong syntax, but your question didn't indicate that you'd tried anything and had a problem-- instead it asked: "How do I do this?" Quote Link to comment https://forums.phpfreaks.com/topic/233760-explode-string-and-use-as-array/#findComment-1201784 Share on other sites More sharing options...
chaseman Posted April 14, 2011 Author Share Posted April 14, 2011 My question was clear enough for the first poster to answer it with ease. I really didn't know how to do this, because I have never done it before. So what would be the obvious choice here? To simply ask how to do it. This not a why isn't it working question. die ('Have a nice day'); Quote Link to comment https://forums.phpfreaks.com/topic/233760-explode-string-and-use-as-array/#findComment-1201796 Share on other sites More sharing options...
kenrbnsn Posted April 15, 2011 Share Posted April 15, 2011 Actually, I almost missed seeing the original brackets and was about to say that you had the correct syntax... Ken Quote Link to comment https://forums.phpfreaks.com/topic/233760-explode-string-and-use-as-array/#findComment-1201852 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.