Hi,

I have an array (2=>50, 231=>63, 235=>121)

How do I change the second item?

Thanks,

Dave

$arr[2]=150;
$arr[231]=163;
$arr[235]=1121;
$arr[2]=150;
$arr[231]=163;
$arr[235]=1121;

Um. Yes.

$numbers=(2=>50, 231=>63, 235=>121);
foreach($numbers as $number){
  if($number==63){
    $number=163;
  }
}

Of course if I knew that key 231 held the number to be changed, it would be as easy as you suggest.

Sorry I didn't make myself clear!

(And, indeed, thanks for the response!) :~)

Um. Yes.

$numbers=(2=>50, 231=>63, 235=>121);
foreach($numbers as $number){
  if($number==63){
    $number=163;
  }
}

Of course if I knew that key 231 held the number to be changed, it would be as easy as you suggest.

Sorry I didn't make myself clear!

(And, indeed, thanks for the response!) :~)

Actually, just answered my own question:

$numbers=(2=>50, 231=>63, 235=>121);
foreach($numbers as $key=>$number){
  if($number==63){
    $numbers[$key]=163;
  }
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.