Register now or log in to join your professional community.
If I have this array array(1,2,3); How can I convert this integer value to string array("1","2","3")
use int($value) or intval($value)
You have2 questions actually.1 in title and other is in description. You don't define in which language you want to do so either in JS, PHP, ASP or any other language so I am a little bit confused to answer :).
Let me try to answer your both questions.
You can convert an INT array to String array in PHP using following way:
- There is not built-in function available in PHP to convert it directly so you need to use your own logic to acheive your goal. So my logic is:
<?php
1st Way:
$a = array(1,2,3);
for( $i =0; $i < count( $a ); $i++ ){ $c[$i] = (string) $a[$i];}
var_dump( $a );
var_dump( $c )
2nd Way:
$a = array(1,2,3);$b = '"'.implode('","', $a).'"';$c = explode(",", $b);
var_dump( $a );
var_dump( $c );
// Reverse this process to convert a String array to INT array.
$a = array("1","2","3");for( $i =0; $i < count( $a ); $i++ ){ $c[$i] = (int) $a[$i];}
var_dump( $a );
var_dump( $c );
?>
Please check this:
string[] arInfo = { "1", "2", "3" };
int[] iarInfo = new int[3];
for (int i =0; i < arInfo.Length; i++)
{
iarInfo[i] = Convert.ToInt32(arInfo[i]);
Console.Write(iarInfo[i]);
}
i hope it will work for you.
public static void main(String[] s)throws Exception
{
int a[]={1,2,3};
String a1[]=new String[3];
for (int i =0; i <3; i++)
{
a1[i]=Integer.toString(a[i]);
}
}
You can use Convert.ToInt32
for ( int i=0;i< a_array.length ; i++) {
Console.writeline(convert.toInt32(a_array[i].toString())
}
int=arry("1","2","3");
string=sum;
sum=array[0][1]+[0][2]+........}
Have you done casting or try this example:
int[] intarray ={1,2,3,4,5};string[] result = intarray.Select(x=>x.ToString()).ToArray();
public static void main(String[] args)throws Exception{ int a[]={1,2,3}; String aa[]=new String[a.length]; for (int i =0; i < a.length; i++) { aa[i]=Integer.toString(a[i]); } }
Assalmou Alykom ,
There is3 way to convert value in php
1 - changing variable's data type : settype($var , 'string')
2 - changing type by casting : (string) $var
3 - changing by this function strval($var)
for apply it easy i make this exmple ,
____________________________________________________________________
<?php
$array = [1,2,3,4] ;
var_dump($array );
$array = array_map("IntegerToString", $array);
var_dump($array );
function IntegerToString($n)
{
settype($n, 'string');
return $n ;
}
__________________________________________________________________________
and for result
array (size=4)0 => int 11 => int 22 => int 33 => int 4array (size=4)0 => string '1' (length=1)1 => string '2' (length=1)2 => string '3' (length=1)3 => string '4' (length=1)
Assalmou alykom
try this one
$string = array("1","2","3");
$integers = array_map('intval', $string);
var_dump($integers);
Do you need help in adding the right keywords to your CV? Let our CV writing experts help you.