techtheatre Posted May 5, 2007 Share Posted May 5, 2007 I have a variable that contains all the possible options for order status, each separated with the pipe "|" character. The status contains characters and spaces. An example is below. I am trying to ONLY get the first option (everything up to the first pipe character...not including the pipe). I have written the code below as a first attempt, but am sure that there is a MUCH better way to do this. Thanks. $OrderStatusTypes = "Awaiting Confirmation|Processing|Shipped|Cancelled"; $StatusArray = split('[|]', $OrderStatusTypes); $DefaultStatus = $StatusArray[0]; I want the value of $DefaultStatus to be Awaiting Confirmation (though this will change if the variable is changed. Quote Link to comment Share on other sites More sharing options...
techtheatre Posted May 5, 2007 Author Share Posted May 5, 2007 I have found a temporary solution, but there is probably a more efficient method...here is what i am using (it works) at the moment...let me know if there is a more elegant way to do this. $OrderStatusTypes = "Awaiting Confirmation|Processing|Shipped|Cancelled"; $StatusArray = explode("|", $OrderStatusTypes); echo "DEFAULT STATUS: ".$StatusArray['0']; Quote Link to comment Share on other sites More sharing options...
effigy Posted May 7, 2007 Share Posted May 7, 2007 Why not use an array? Quote Link to comment Share on other sites More sharing options...
techtheatre Posted May 7, 2007 Author Share Posted May 7, 2007 That is what i have done already...i thought there might be a better way. If not then i will mark this as solved, but i am waiting to see if anyone knows a more direct approach...this method has two parts and ends up with a left-over array that is unused after one line fo code...so it seems that there might be a way to do it without the "scraps"... The array approach certainly works and is what i have implimented in the meantime... If this really is the best option, let me know and i will close this post. Quote Link to comment Share on other sites More sharing options...
effigy Posted May 7, 2007 Share Posted May 7, 2007 An array should be the best fit when working with a list of items. I can't advise further without knowing the bigger picture. Quote Link to comment 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.