함수 print_r()


1 Bash[ | ]

ARR=("John Smith" "Jane Doe" "Mike Barnes" "Kevin Patterson")
echo ${ARR[@]}
# John Smith Jane Doe Mike Barnes Kevin Patterson
echo ${ARR[*]}
# John Smith Jane Doe Mike Barnes Kevin Patterson
for VALUE in "${ARR[@]}"; do echo $VALUE; done
# John Smith
# Jane Doe
# Mike Barnes
# Kevin Patterson
printf '%s\n' "${ARR[@]}"
# John Smith
# Jane Doe
# Mike Barnes
# Kevin Patterson

2 C++[ | ]

#include <iostream>
using namespace std;
int main() {
    int nums[] = {3,4,2,1};
    int len = sizeof(nums)/sizeof(int);
    for(int i=0; i<len; i++) cout << nums[i] << " ";
    // 3 4 2 1 
}

3 Java[ | ]

int[] foo = {1, 2, 3};
System.out.println(Arrays.toString(foo));
// [1, 2, 3]
String[] foo = {"one", "two", "three"};
System.out.println(Arrays.toString(foo));
// [one, two, three]

4 JavaScript[ | ]

var foo = new Array( 3.14, 777, 'Hello', -0.511, 'World');
console.log(foo); 
// [3.14, 777, "Hello", -0.511, "World"]
<script src="https://raw.github.com/kvz/phpjs/master/functions/strings/echo.js"></script>
<script src="https://raw.github.com/kvz/phpjs/master/functions/var/print_r.js"></script>
<script>
var foo = new Array( 3.14, 777, 'Hello', -0.511, 'World');
print_r(foo);
// Array ( [0] => 3.14 [1] => 777 [2] => Hello [3] => -0.5 [4] => World )
</script>

5 Lua[ | ]

function print_r(arr, indentLevel)
    local str = ""
    local indentStr = "#"

    if(indentLevel == nil) then
        print(print_r(arr, 0))
        return
    end

    for i = 0, indentLevel do
        indentStr = indentStr.."\t"
    end

    for index,value in pairs(arr) do
        if type(value) == "table" then
            str = str..indentStr..index..": \n"..print_r(value, (indentLevel + 1))
        else 
            str = str..indentStr..index..": "..value.."\n"
        end
    end
    return str
end

print_r( { 3.14, 777, 'Hello', -0.511, 'World' } )
-- #	1: 3.14
-- #	2: 777
-- #	3: Hello
-- #	4: -0.511
-- #	5: World

6 Perl[ | ]

use Data::Dumper;

my $foo = [3.14, 777, 'Hello', -0.5, 'World'];
print Dumper($foo);
# $VAR1 = [
#           '3.14',
#           777,
#           'Hello',
#           '-0.5',
#           'World'
#         ];

7 PHP[ | ]

$foo = [3.14, 777, 'Hello', -0.5, 'World'];
print_r($foo);
# Array
# (
#     [0] => 3.14
#     [1] => 777
#     [2] => Hello
#     [3] => -0.5
#     [4] => World
# )

8 Python[ | ]

foo = [3.14, 777, 'Hello', -0.5, 'World']
print foo
# [3.1400000000000001, 777, 'Hello', -0.5, 'World']

9 Ruby[ | ]

require 'pp'
foo = [3.14, 777, 'Hello', -0.5, 'World']
pp foo
# [3.14, 777, "Hello", -0.5, "World"]

10 같이 보기[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}