PHP-এ একটি অ্যারেতে সমস্ত স্ট্রিং ট্রিম করতে, কোডটি নিম্নরূপ-
উদাহরণ
<?php $arr = array( " John ", "Jacob ", " Tom ", " Tim "); echo "Array with leading and trailing whitespaces...\n"; foreach( $arr as $value ) { echo "Value = $value \n"; } $result = array_map('trim', $arr); echo "\nUpdated Array...\n"; foreach( $result as $value ) { echo "Value = $value \n"; } ?>
আউটপুট
এটি নিম্নলিখিত আউটপুট-
তৈরি করবেArray with leading and trailing whitespaces... Value = John Value = Jacob Value = Tom Value = Tim Updated Array... Value = John Value = Jacob Value = Tom Value = Tim
উদাহরণ
এখন আরেকটি উদাহরণ দেখা যাক -
<?php $arr = array( " Kevin ", "Katie ", " Angelina ", " Jack "); echo "Array with leading and trailing whitespaces...\n"; foreach( $arr as $value ) { echo "Value = $value \n"; } array_walk($arr, create_function('&$val', '$val = trim($val);')); echo "\nUpdated Array...\n"; foreach($arr as $key => $value) print($arr[$key] . "\n"); ?>
আউটপুট
এটি নিম্নলিখিত আউটপুট-
তৈরি করবেArray with leading and trailing whitespaces... Value = Kevin Value = Katie Value = Angelina Value = Jack Updated Array... Kevin Katie Angelina Jack