Dale_G Posted June 21, 2008 Share Posted June 21, 2008 Hey everyone, quick question. Alright, for example, let's say I have an array of random text. $mytext = array( 'ololol', 'hilol', 'WTFBBQ', 'OMFGPWNISw##@234' ); Right? And I have a function that adds bold tags to text. function bold_text( $text ) { return '<b>'.$text.'</b>'; } Now, how can I apply the function to every item in the array of $mytext? Yes I know I could just do it manually as I would only have to do it 4 times, but I have a more complicated use for this using an array that contains hundreds of items in the array. So uh, thanks for the help fellow PHPers! Quote Link to comment https://forums.phpfreaks.com/topic/111211-solved-perform-a-function-with-every-bit-of-data-in-an-array/ Share on other sites More sharing options...
Dale_G Posted June 21, 2008 Author Share Posted June 21, 2008 Alright, I got it. foreach ( $mytext as $boldtext ) { echo bold_text( $boldtext ); } That was simple. Quote Link to comment https://forums.phpfreaks.com/topic/111211-solved-perform-a-function-with-every-bit-of-data-in-an-array/#findComment-570810 Share on other sites More sharing options...
sasa Posted June 21, 2008 Share Posted June 21, 2008 try <?php $mytext = array( 'ololol', 'hilol', 'WTFBBQ', 'OMFGPWNISw##@234' ); function bold_text( &$text ) { $text = '<b>'.$text.'</b>'; } array_walk($mytext, 'bold_text'); print_r($mytext); ?> Quote Link to comment https://forums.phpfreaks.com/topic/111211-solved-perform-a-function-with-every-bit-of-data-in-an-array/#findComment-570816 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.