<?php
$codes = array('F_NAME', 'F_PHONE', 'F_EMAIL', 'F_ADDRESS');
ob_start();
echo "#F_NAME#";
echo "#F_PHONE#";
$props = ob_get_contents();
ob_end_clean();
foreach ($codes as $code)
{
switch ($code)
{
case "F_NAME":
$str = 0;
break;
case "F_PHONE":
$str = 1;
break;
}
$props = str_replace(
'#'.$code.'#',
$str,
$props);
}
echo $props."\n";
ob_start();
echo "#F_EMAIL#";
echo "#F_ADDRESS#";
$props = ob_get_contents();
ob_end_clean();
foreach ($codes as $code)
{
switch ($code)
{
case "F_EMAIL":
$str = 2;
break;
case "F_ADDRESS":
$str = 3;
break;
}
$props = str_replace(
'#'.$code.'#',
$str,
$props);
}
echo $props."\n";
$codes = array('F_NAME' => 1, 'F_PHONE' => 2, 'F_EMAIL' => 3, 'F_ADDRESS' => 4);
$props = '#F_NAME# #F_PHONE# #F_EMAIL# #F_ADDRESS#';
$codes_keys = array_map(function($item){ return "#{$item}#"; }, array_keys($codes));
$props = str_replace(
$codes_keys,
array_values($codes),
$props);
echo $props."\n";