����ת��

PHP�в���Ҫ��Ҳ��֧�֣��ڱ�������ʱ����ʽ����������;һ������������ȡ��������ֵ�����͡�Ҳ����˵,����������var ����һ���ַ���ֵ��var �ͳ�Ϊ�ַ���������������ָ���һ������ֵ��var, ���ͱ����һ�����ͱ�����

һ��PHP�Զ�����ת���������Ǽӷ������� '+'������κ�һ����������double��,�����еIJ������� double����������, ���Ҳ��double�͵ġ��������еIJ�������integer����������, ���Ҳ��integer�͵ġ�ע�⣺���������������Ͳ������仯;���ͱ任���ڼ���ʱ����

$foo = "0";  // $foo is a string (ASCII 48)
$foo++;      // $foo is the string "1" (ASCII 49)
$foo += 1;   // $foo is now an integer (2)
$foo = $foo + 1.3;  // $foo is now a double (3.3)
$foo = 5 + "10 Little Piggies";    // $foo is a double (15)
$foo = 5 + "10 Small Pigs";   // $foo is an integer (15)
     

��������������������,�뿴�ַ���ת��.

�����Ҫǿ��ָ��һ��������Ϊ�ض����ͽ��м���,�뿴 Type casting ���֡�Ҫ�ı����������,�뿴settype() ������

���Ա�������

��ΪPHP������Ҫ���������ͼ���������ת��,����һ���������������Ͳ���һ�ɲ���ġ�PHP����һϵ�� ���ͼ�⺯���� gettype(), is_long(), is_double(),is_string(),is_array(),��is_object()��

ǿ������ת��

PHP�е�ǿ������ת����C��һ��: ����Ҫ��������ǿ��ת���ı���ǰ��������д����Ҫ����������

$foo = 10;   // $foo is an integer
$bar = (double) $foo;   // $bar is a double
      

������ǿ��ת����:

ע�⣺�����п��Ժ���tab��ո�,����ĺ�����������:

$foo = (int) $bar;
$foo = ( int ) $bar;
     

�ַ���ת��

���ַ�����Ϊ��ֵ���ͼ���ʱ,�����ֵ�����Ͱ����·�ʽ������

����ַ����а����κ�'.', 'e',��'E'�ַ�������Ϊdouble���ͼ��㡣���򣬾���Ϊinteger���ͼ��㡣

��ֵ���ַ����ʼ��������ַ����ǺϷ�������,��ʹ�ø�ֵ������ֵΪ 0 ���Ϸ���������һ������λ����ѡ�������һλ��λ����(Ҳ�ɺ���һ��ʮ���Ƶ�С����), ���һλ��ѡ��ָ����ָ����һ�� 'e' �� 'E'���һ���򼸸����֡�

$foo = 1 + "10.5";      // $foo is a double (11.5)
$foo = 1 + "-1.3e3";    // $foo is a double (-1299)
$foo = 1 + "bob-1.3e3"; // $foo is a double (1)
$foo = 1 + "bob3";      // $foo is an integer (1)
$foo = 1 + "10 Small Pigs";     // $foo is an integer (11)
$foo = 1 + "10 Little Piggies"; // $foo is a double (11); the string contains 'e'
      

Ҫ��ø������ת������Ϣ,�뿴Unix manҳ���strtod(3)��