EchoFool Posted July 10, 2008 Share Posted July 10, 2008 I have a value which carries to bits of infomation seperated by | symbol. But I do not know how to split them into two different variables. <?php $ID = 'Country|23'; $IDType = explode('|', $ID, -1); $IDType[0] = $Type; $IDType[1] = $TypeID; ?> What im trying to get is $Type = Country; $TypeID = 23; But it is not working, what am i doing wrong ? Link to comment https://forums.phpfreaks.com/topic/114184-solved-array-help/ Share on other sites More sharing options...
ratcateme Posted July 10, 2008 Share Posted July 10, 2008 you want this <?php $ID = 'Country|'.23; $IDType = explode('|', $ID,); $Type = $IDType[0]; $TypeID = $IDType[1]; ?> i don't think this will work $IDType[0] = $Type; it should try to set $IDType[0] to $Type instead. Scott. Link to comment https://forums.phpfreaks.com/topic/114184-solved-array-help/#findComment-587105 Share on other sites More sharing options...
gijew Posted July 10, 2008 Share Posted July 10, 2008 You have it backwords a bit. Try this. <?php $ID = 'Country|'.23; $IDType = explode('|', $ID, -1); $Type = $IDType[0]; $TypeID = $ID Type[1]; ?> Link to comment https://forums.phpfreaks.com/topic/114184-solved-array-help/#findComment-587106 Share on other sites More sharing options...
rhodesa Posted July 10, 2008 Share Posted July 10, 2008 <?php $ID = 'Country|23'; list($Type,$TypeID) = explode('|', $ID, 2); ?> Link to comment https://forums.phpfreaks.com/topic/114184-solved-array-help/#findComment-587108 Share on other sites More sharing options...
EchoFool Posted July 10, 2008 Author Share Posted July 10, 2008 Thankyou for your reply! I am getting this how ever now as an error: Notice: Undefined offset: 1 on line 57 <?php $IDType = explode('|', $ID, -1); $Type = $IDType[0]; $ID = $IDType[1]; //this line ?> Link to comment https://forums.phpfreaks.com/topic/114184-solved-array-help/#findComment-587110 Share on other sites More sharing options...
ratcateme Posted July 10, 2008 Share Posted July 10, 2008 why do you have the -1 in the explode remove it then try Scott. Link to comment https://forums.phpfreaks.com/topic/114184-solved-array-help/#findComment-587114 Share on other sites More sharing options...
EchoFool Posted July 10, 2008 Author Share Posted July 10, 2008 Scott, I don't know I saw it in the php site so presumed it was needed. But it is fixed now i have removed it. So thankyou for that! Link to comment https://forums.phpfreaks.com/topic/114184-solved-array-help/#findComment-587117 Share on other sites More sharing options...
Barand Posted July 11, 2008 Share Posted July 11, 2008 <?php $ID = 'Country|23'; list($Type,$TypeID) = explode('|', $ID, 2); ?> It happens all the time - the best solution is totally ignored. Link to comment https://forums.phpfreaks.com/topic/114184-solved-array-help/#findComment-587125 Share on other sites More sharing options...
rhodesa Posted July 11, 2008 Share Posted July 11, 2008 <?php $ID = 'Country|23'; list($Type,$TypeID) = explode('|', $ID, 2); ?> It happens all the time - the best solution is totally ignored. thanks for the props Link to comment https://forums.phpfreaks.com/topic/114184-solved-array-help/#findComment-587168 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.