Surely there must be a simple answer

software development

#1

Hi

My name is Phil and I’ve been programming in php for some time now, but…

here is something simple that does not work as it should:

$verif_array[1]= “Ehet”;
$rightanswer[1]= substr($verif_array[1],1);
echo “verif=” . substr($verif_array[1],1);
echo “–right=” . $rightanswer[1];

And here is what I get : verif=het–right=h

Why does $rightanswer[1] only take the first letter of “het”?

For me it’s a mystery! Furthermore it works fine on my xampp server.

Any ideas?

Thanks!
Phil


#2

If I remember right, the “E” would be at array[0] not [1].
Silk

My website


#3

[quote]here is something simple that does not work as it should:

$rightanswer[1]= substr($verif_array[1],1);

For me it’s a mystery! Furthermore it works fine on my xampp server.[/quote]
It’s not a mystery to me. What you observe is expected behavior if $rightanswer is a string and not an array. You need to perform a code review. Your logic is probably flawed and $rightanswer is not getting defined or declared properly before you get to that point.

:cool: openvein.org -//- One-time [color=#6600CC]$50.00 discount[/color] on [color=#0000CC]DreamHost[/color] plans: Use ATROPOS7


#4

[quote]<?
$verif_array[1]= “Ehet”;
$rightanswer[1]= substr($verif_array[1],1);
echo “verif=” . substr($verif_array[1],1);
echo “–right=” . $rightanswer[1];
?>[/quote]
Returns verif=het–right=het

Maximum Cash Discount on any plan with MAXCASH