What is the equivalent of php's print_r() in AHK? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
DanielToward13
Posts: 74
Joined: 18 May 2017, 10:56

What is the equivalent of php's print_r() in AHK?

26 May 2017, 05:23

I want to see human-readable information about an object. What are the keys, values and the structure. I exactly need the equivalent of PHP's print_r() function.

PHP Code:

Code: Select all

<pre>
<?php
$a = array ('a' => 'apple', 'b' => 'banana', 'c' => array ('x', 'y', 'z'));
print_r ($a);
?>
</pre>
Output:

Code: Select all

<pre>
Array
(
    [a] => apple
    [b] => banana
    [c] => Array
        (
            [0] => x
            [1] => y
            [2] => z
        )
)
</pre>
User avatar
tank
Posts: 3122
Joined: 28 Sep 2013, 22:15
Location: CarrolltonTX
Contact:

Re: What is the equivalent of php's print_r() in AHK?

26 May 2017, 09:27

PHP does many things for which there is no AHK equivilent. printing to the screen is one. I suppose your refering to how print_r can be used to dump objects and arrays
You would have to build this functionality as a script or function
We are troubled on every side‚ yet not distressed; we are perplexed‚
but not in despair; Persecuted‚ but not forsaken; cast down‚ but not destroyed;
Telegram is the best way to reach me
https://t.me/ttnnkkrr
If you have forum suggestions please submit a
Check Out WebWriter
DanielToward13
Posts: 74
Joined: 18 May 2017, 10:56

Re: What is the equivalent of php's print_r() in AHK?

26 May 2017, 09:42

anyone who can help me with this script?
HotKeyIt
Posts: 2364
Joined: 29 Sep 2013, 18:35
Contact:

Re: What is the equivalent of php's print_r() in AHK?  Topic is solved

26 May 2017, 10:04

Try this:

Code: Select all

obj:={a:"apple", b:"banana", c:["x", "y", "z"]}
MsgBox % print_r(obj)
print_r(arr,indent:=""){
  if indent
    out.="Array`n" indent "(`n"
  for k,v in arr
    out.=indent "[" k "] => " (IsObject(v)?print_r(v,indent "`t"):v) "`n"
  return RTrim(out,"`n") (indent?"`n" indent ")":"")
}
DanielToward13
Posts: 74
Joined: 18 May 2017, 10:56

Re: What is the equivalent of php's print_r() in AHK?

26 May 2017, 10:29

Thanks HotKeyIt. You have been a great help. I had some unknown objects that I couldn't figure them out. This helped me to retrieve them based on their structure.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: filipemb, mikeyww, PsysimSV and 308 guests