php 배열 질문좀 드릴께요 ㅠㅠ 정보
php 배열 질문좀 드릴께요 ㅠㅠ본문
php 공부하기 시작했는데요.
배열 이해가 안가서 이렇게 글남깁니다 ㅠ
C언어에서는 배열을 선언할때,
int array[10];
이렇게 선언해주면 40byte의 공간이 생기잖아요.
물론 컴터마다 다르겠지만요;
그런데 php 에서는
배열을 선언할때
$array[0] = "abc"; 하면, 인덱스 0에 abc가 다 저장된다고 하네요;
그러면 그중에 b만 출력하려면 어찌해야하나용 ㅇㅅㅇ?
C에서 char 형으로 배열을 선언하면, 각 인덱스마다 영어 한문자씩 저장되니까,
출력할때 해당 인덱스를 출력해주면 되지만,
php 에서는 어찌해야하는건가요?
제가 php 배열을 잘못이해하고 있는건가요?
C는 처음에 배열을 선언할때, 메모리크기를 정하지만,
php 는 정해지지 않고, 가변적인 크기 인가요?
아 머리 아프네요 -_ -; 배열이 이해안가요 ㅠㅠㅠ
추천
0
0
댓글 7개
$array[0] = "abc";
=> string etc = 'abc';개념과 동일
php 에서는 단지 변수에 초기값 부여
=> string etc = 'abc';개념과 동일
php 에서는 단지 변수에 초기값 부여
$array[0] = "abc" 이면
echo $array[0][0]; //a
echo $array[0][1]; //b
echo $array[0][2]; //c
이렇게 됩니다
echo $array[0][0]; //a
echo $array[0][1]; //b
echo $array[0][2]; //c
이렇게 됩니다
http://www.php.net/manual/en/language.types.string.php
String access and modification by character
Characters within strings may be accessed and modified by specifying the zero-based offset of the desired character after the string using square array brackets, as in $str[42]. Think of a string as an array of characters for this purpose. The functions substr() and substr_replace() can be used when you want to extract or replace more than 1 character.
String access and modification by character
Characters within strings may be accessed and modified by specifying the zero-based offset of the desired character after the string using square array brackets, as in $str[42]. Think of a string as an array of characters for this purpose. The functions substr() and substr_replace() can be used when you want to extract or replace more than 1 character.
감사합니다 ㅠㅠㅠㅠㅠㅠㅠㅠㅠ
저도 그 기분 잘 아는데
C하신 분들이 php 하거나 그 반대로 할때
이해도 부분이 홍역 비슷하게 앓더군요 ㅜㅜ
특히 말씀 하신 배열 부분이 가장 머리가 아플텐데
php가 그 만큼 배열은 `환상적이다`라고 할 수 있습니다.
C하신 분들이 php 하거나 그 반대로 할때
이해도 부분이 홍역 비슷하게 앓더군요 ㅜㅜ
특히 말씀 하신 배열 부분이 가장 머리가 아플텐데
php가 그 만큼 배열은 `환상적이다`라고 할 수 있습니다.
환상적이다에 전적으로 동감합니다.