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
https://forums.phpfreaks.com/topic/42502-strings-and-arrays/
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
https://forums.phpfreaks.com/topic/42502-strings-and-arrays/#findComment-206225
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.