即使是PHP的學生!搜索 這個,但沒有得到任何答覆因此發佈會將qPHP:數組格式部分sprintf或vprintf
我知道
sprintf (string format [, mixed args])
sprintf描述:返回根據格式化字符串 格式生成的字符串。
和
vsprintf (string format, array args)
雖然這些都還不夠好,我只是通過一個問題
跑有什麼簡單的方法來
(我的意思是比迭代和sprintf
每不錯) 「」返回根據格式化陣列格式生成的陣列。「(描述:從sprintf複製)
我有一個大致的$產品陣列
$product = array(
"p_id" => '%s',
"u_price" => '%s',
"qty" => '%d'
);
$newProductArray1= sprintf_special($product,"Tomato","30","12");
$newProductArray2= sprintf_special($product,"Carrot","20","10");
這樣
$newProductArray1= (
"p_id" => 'Tomato',
"u_price" => '30',
"qty" => '12'
)
$newProductArray2= (
"p_id" => 'Carrot',
"u_price" => '20',
"qty" => '10'
)
注:我不想做一個產品類,但是! :)
沒有,有沒有這樣的事情。 '$ product ['p_id'] ='Tomato''等等,或者只是以'$ product = array('p_id'] =>'Tomato'等開頭來定義數組。 )'。 –
你必須迭代! – Nifty
@Nifty等待一些瘋狂的人回答這個問題,通過goooogling眨眼...... –