0perator Posted June 22, 2008 Share Posted June 22, 2008 if i were to have a table in a databse called `challeneges` the fields were ____________________ |username | completed| ----------------------- username b1, b2, b3 and i have $done = mysql_fetch_array($sql); now, $done['completed'] = b1,b2,b3 how do i search the array of $done['completed'] to see if it contains the string b1 i was thinkning explode around the , am i right? Link to comment https://forums.phpfreaks.com/topic/111317-array/ Share on other sites More sharing options...
thebadbad Posted June 22, 2008 Share Posted June 22, 2008 Yes. But you must decide if the challenges (?) are separated by a comma, or by a comma and a space. Use in_array() to search the exploded string. Link to comment https://forums.phpfreaks.com/topic/111317-array/#findComment-571428 Share on other sites More sharing options...
0perator Posted June 22, 2008 Author Share Posted June 22, 2008 ah right yes, they will be spearated by only a comma. thanks Link to comment https://forums.phpfreaks.com/topic/111317-array/#findComment-571429 Share on other sites More sharing options...
0perator Posted June 22, 2008 Author Share Posted June 22, 2008 okay, if b1 is not in there, how do i append it to the mysql_fetch_array() without affecting what is already there. Link to comment https://forums.phpfreaks.com/topic/111317-array/#findComment-571434 Share on other sites More sharing options...
thebadbad Posted June 22, 2008 Share Posted June 22, 2008 If you want to append to a string, simply: <?php $str = 'b2,b3'; $str .= ',b1'; echo $str; //b2,b3,b1 ?> To append an element to an array: <?php $array = array('b2', 'b3'); $array[] = 'b1'; //$array is now array('b2', 'b3', 'b1'); ?> Link to comment https://forums.phpfreaks.com/topic/111317-array/#findComment-571443 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.