1

Basically I want some function like array_as_php which is essentially the inverse of eval:

$array = array( '1' => 'b', '2' => 'c' );
echo array_as_php($array);

will print the following eval-able string:

array( '1' => 'b', '2' => 'c' )
4
  • What are you planning on using this for? Commented Feb 5, 2011 at 3:37
  • 3
    Did you mean array ('1' => 'b', '2' => 'c' ); instead of array( '1': 'b', '2': 'c' );? Commented Feb 5, 2011 at 3:37
  • is there a reason print_r won't work? Commented Feb 5, 2011 at 3:40
  • @madmik3: it is. print_r results are not evalable Commented Feb 5, 2011 at 3:40

1 Answer 1

7

var_export() is what you are looking for.

$array = array ('1' => 'b', '2' => 'c' );
echo var_export($array, true);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.