Jump to content

Strings and arrays...?


Patrick3002

Recommended Posts

 


<?php
$var1="abcdefghij";
for ($i=0;$i<strlen($var1);$i++) {
     
 echo $var1[$i].'<br>';
}
?>

 

Using that code above... How would i select more than one letter at a time and put it into individual strings for example:

 

If i used that code and wanted to be able to so this:

 

echo $var1[abc]; ( outputs 'abc' )

echo $var1[def]; ( outputs 'def' )

echo $var1[ghij]; ( outputs 'ghij' )

 

 

How would i modify that script to do that?

Link to comment
Share on other sites

I can't really see a pattern here... Define exactly what the function you are looking for should make.

Anyway, if you know what letters you want to display (IE- you dont need to display them by position or something), just output them directly...

 

Orio.

Link to comment
Share on other sites

Something like this....

 

 


$numbers = array("1","2","3","4","5");

echo $numbers[0]; (outputs 1)
echo $numbers[1]; (outputs 2)

etc...

 

But instead i can use strings in the array func... is that right??

 

so like this: array("$var1","$var2","$var3");

 

can i use vars in an array func??

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.