私の質問が私が求めていることを適切に説明していることを願っています...
これが状況です。値を持つ次の配列があります。
categories['t-shirts'] = 10
categories['shorts'] = 11
...
clothing[0] = 't-shirts'
clothing[1] = 'shorts'
...
衣類配列 (T シャツ、ショーツ) の値を、categorys 配列から一致する番号に置き換えたいと考えています。
乾杯
foreach($clothing as $key => $val){
if(isset($categories[$val])){
$clothing[$key] = $categories[$val];
}
}
$count = count($clothing);
for($i=0; $i<$count; $i++)
$clothing[$i] = (array_key_exists($clothing[$i], $categories))
? $categories[$clothing[$i]] : 0;
カウントなしの$clothingsを0に設定する場合
$categories = array();
$categories['t-shirts'] = 10;
$categories['shorts'] = 11;
$clothing = array();
$clothing[0] = 't-shirts';
$clothing[1] = 'shorts';
array_walk($clothing,
function(&$value) use($categories) {
if (isset($categories[$value]))
$value = $categories[$value];
}
);
var_dump($clothing);
あなたの質問から、それは次のようになります
$newArray=array_keys($originalArray);
トリックを行う必要があります。
シンプルなphpを使用できます
categories[clothing[0]] = "some value"