how do you prepend a value to a string.
For example
$a='great';
prepend 'pop ' to $a;
$a == 'pop great';
sort of like the reverse of .=
Printable View
how do you prepend a value to a string.
For example
$a='great';
prepend 'pop ' to $a;
$a == 'pop great';
sort of like the reverse of .=
So I don't get what you mean.
When you use .= have the text go in the beginning not front?
yes.
What I want to do is the opposite. I want to know if there is some sort of function or way that I can prepend the string so that you can add 'so ' to $a to make $a become 'so what if?'.Code:$a='what';
$a.=' if?';
//$a becomes 'what if?';
Well, why dont you just:
$a='what';
$a.=$a.' if?';
//$a becomes 'what if?';
because $a already has a pregenerated value. Nice thought though. I just found this simple answer though ;)
$a='if?';
$b='what ';
$a="$b$a";
//$a becomes "what if?"
Isn't that just like what I posted?
EDIT: Try what I posted.
No. You appended the string. I prepended the string. Since it is short here is the code that I am using it in:
to do what you suggested would erase the passed value, which is why I needed to prepend the string.Code:<?php
$a=0;$b='0000000';
foreach ($_POST as $field[] => $value[])
{
if (strpos($field[$a],'check')===0)
else $value[$a]="$b$value[$a]";
echo "$field[$a] = $value[$a]<br>";$a++;
}
echo "pp $_POST[loot_Lasl] pp";
?>
P.S. the script is only in its infancy, so no need to critique it. I am merely designing it right now.
o then you would judt:
PHP Code:$a='what';
$a=$a.' if?';
//$a becomes 'what if?';
Code:$a = ' if?';
$a = 'What' . $a;
$a .= $bis just a short form of$a = $a . $b.
that works too :)