Student of PHP Even Now ! Searched for this but haven't got any answer So posting the Q
i know about
sprintf ( string format [, mixed args])
sprintf Description :Returns a string produced according to the formatting string format.
and
vsprintf ( string format, array args)
Though these are pretty good enough i just ran through a problem
is there any simple way to (i mean a pretty good than iteration and sprintf
each)
"Returns an array produced according to the formatting array format. " ( Desc:copied from sprintf )
i have a general $product array
$product = array(
"p_id" => '%s',
"u_price" => '%s',
"qty" => '%d'
);
$newProductArray1= sprintf_special($product,"Tomato","30","12");
$newProductArray2= sprintf_special($product,"Carrot","20","10");
So that
$newProductArray1= (
"p_id" => 'Tomato',
"u_price" => '30',
"qty" => '12'
)
$newProductArray2= (
"p_id" => 'Carrot',
"u_price" => '20',
"qty" => '10'
)
NB: i don't want to make a product class though! :)
$product['p_id'] = 'Tomato'
and the like for the rest, or just define the array that way to begin with$product = array('p_id'] => 'Tomato', etc....)
.