2016-06-12 10 views
0

PHPで特定の配列の値を変更する方法はありますか?私は別の何かにイメージ値を変更する必要が配列の値を変更してPHPのデータベースに保存

array (
    0 => 
    array (
    'name' => 'Mia Wasikowska', 
    'id' => 'nm1985859', 
    'url' => 'http://www.imdb.com/name/nm1985859/', 
    'image' => 'http://ia.media-imdb.com/images/M/[email protected]_V1_.jpg', 
    'character' => 'Alice Kingsleigh', 
), 
    1 => 
    array (
    'name' => 'Johnny Depp', 
    'id' => 'nm0000136', 
    'url' => 'http://www.imdb.com/name/nm0000136/', 
    'image' => 'http://ia.media-imdb.com/images/M/[email protected]@._V1_.jpg', 
    'character' => 'Hatter Tarrant Hightopp', 
), 
    2 => 
    array (
    'name' => 'Helena Bonham Carter', 
    'id' => 'nm0000307', 
    'url' => 'http://www.imdb.com/name/nm0000307/', 
    'image' => 'http://ia.media-imdb.com/images/M/[email protected]@._V1_.jpg', 
    'character' => 'Iracebeth', 
), 
    3 => 
    array (
    'name' => 'Anne Hathaway', 
    'id' => 'nm0004266', 
    'url' => 'http://www.imdb.com/name/nm0004266/', 
    'image' => 'http://ia.media-imdb.com/images/M/[email protected]@._V1_.jpg', 
    'character' => 'Mirana', 
), 
) 

:私は作品が配列である情報を投げかけています。これに

'image' => 'http://ia.media-imdb.com/images/M/[email protected]@._V1_.jpg', 

'image' => '/uploads/images/artirst_0214.jpg', 

、最後に私はこのようにそれを持っている必要があります:

array (
    0 => 
    array (
    'name' => 'Mia Wasikowska', 
    'id' => 'nm1985859', 
    'url' => 'http://www.imdb.com/name/nm1985859/', 
    'image' => '/uploads/images/artirst_032.jpg', 
    'character' => 'Alice Kingsleigh', 
), 
    1 => 
    array (
    'name' => 'Johnny Depp', 
    'id' => 'nm0000136', 
    'url' => 'http://www.imdb.com/name/nm0000136/', 
    'image' => '/uploads/images/artirst_07897.jpg', 
    'character' => 'Hatter Tarrant Hightopp', 
), 
    2 => 
    array (
    'name' => 'Helena Bonham Carter', 
    'id' => 'nm0000307', 
    'url' => 'http://www.imdb.com/name/nm0000307/', 
    'image' => '/uploads/images/artirst_0987.jpg', 
    'character' => 'Iracebeth', 
), 
    3 => 
    array (
    'name' => 'Anne Hathaway', 
    'id' => 'nm0004266', 
    'url' => 'http://www.imdb.com/name/nm0004266/', 
    'image' => '/uploads/images/artirst_0214.jpg', 
    'character' => 'Mirana', 
), 
) 

はあなた

答えて

1
$ArrayKeys=array_keys($data); 
$cntKeys=count($ArrayKeys); 
for ($i=0;$i<$cntKeys;$i++) 
{ 
$data[$ArrayKeys[$i]]["image"]="ciro"; 
} 

print_r ($data); 
に感謝例えば、これを変更します

あなたの配列が "データ"と呼ばれるとしましょう。 このようにして、配列のキー(0,1,2 ....)を取得し、それぞれのキーでimg値にアクセスすることができます。 次に、$ dataを使用して値にアクセスできます[key_your_array] ["image"] = "何か"。名前が示唆するように、$ ArrayKeysが配列である、ので、私は

$data[$ArrayKeys[$i]] 

使用して、私は、i番目の要素にアクセスしたい

関連する問題