Jump to content

Overwriting an string pointer with an array item.


law

Recommended Posts

I have some for loops that are rolling through various arrays. When a certain array value satisfies an if statement, I would like to overwrite another array with information from that array.

 

Rough Example:

$num1 = 30; //just example data
$b[3] = 20;
$b[6] = 15;
$a = 120358; //number string given to me

for($i=0; $i < $num1; $i++){
if(isset($b[$i])){ //when it finds that $b has data
$a[$i] = $b[$i]; // I need to replace $a[$i] with b's data. I have a large number of processes that go below this point that rely on $a. What is the best way to do this? The current example sets $a[$i] = 2 NOT 20 because A is a string not really an array.
}
}

 

Ideas? or a fundamental concept issue? I am open to suggestions.

Link to comment
Share on other sites

In this example

 

$a = 120358

a[3] = 3

b[3]  = 20

 

a[3] = b[3]

a[3] = 2      <- not 20

 

I am trying to replace a specific section of a string with essentially another string. Does that make sense?

I would assume there is some functions I am missing. *Going to re-check the manual*

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.