
Native PHP Explode For Each
April 29, 2020
If you use custom field in wordpress, sometime need run the custom field into some function.
<?php
$cars=array("Volvo|100","BMW|100","Toyota|100");
foreach($cars as $key => $value)
{
$arr = explode('|', trim($value));
echo "Car: $arr[0], Price: $arr[1]<br>";
}
?>
Output:
Car: Volvo, Price: 100
Car: BMW, Price: 100
Car: Toyota, Price: 100
Posted in PHP, Wordpress Tweaks