Jump to content

String to Literal Arguments


n00b3

Recommended Posts

Hello,

 

<?php

 

$somestr = "0,1";

$array = array($somestr);

print_r($array);

echo count($array);

 

/* The above code prints out the following:

 

Array

(

[0] => 0,1

}

1

 

  However, I want the following:

 

  Array

  (

[0] => 0

[1] => 1

  }

  2

*/

 

?>

 

How do i get the string "0,1" to act more 'literally'.  That is, I would like the string to be the two arguments into the array function rather than just the one "0,1" argument.

 

The variable $somestr can be any variable type.

 

I tried

array({$somestr})

{array($somestr)}

array((binary) $somestr)

 

But these three attempts resulted in errors or not the desired result.

 

Thanks in advance.

DanK

Link to comment
https://forums.phpfreaks.com/topic/97338-string-to-literal-arguments/
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.