phpsane Posted September 5, 2017 Share Posted September 5, 2017 (edited) Folks, What is an "Element" in php ? I came across the word when researching on the php's "Count" function: https://www.tutorialspoint.com/php/php_function_count.htm These are not useful as they talk about "element in array" etc.: http://php.net/manual-lookup.php?pattern=element&scope=quickref https://www.google.com/search?q=what+is+an+element+in+php+%3F&oq=what+is+an+element+in+php+%3F&aqs=chrome..69i57j69i64.5238j0j7&sourceid=chrome&ie=UTF-8 Let's not talk about "element in any array". Let's just talk about "element" itself. What is the definition of an "element" in php ? And so, to newbies, how can you describe an "Element" in the layman's language without resorting to complex or advanced stuffs ? I'd like to see a few examples of an element in php with very simple & basic coding that is easily understandable to all beginners. I'm sure future newbies would appreciate your hard work! I am sure "elements" not only exist in "arrays" but other stuffs in php too. So, how-about a few examples on these other stuffs too regarding their elements ? Let me tell you why I prefer examples of an element without involving the array. Here: https://www.tutorialspoint.com/php/php_function_count.htm It says: Return Value It returns the number of elements in an array. Example Try out following example − <?php$a[0] = 1;$a[1] = 3;$a[2] = 5;$result = count($a);print($result);?> This will produce the following result − 3 I don't see any elements in that example. I see things in this format: $variable name[array number] = array value; Where is the so-called "element" involved in any of this ? Which part is the "element" ? Which part of the "equation" ? Get a beginner's point of view ? These tutorials are not easy to understand. Thanks! Edited September 5, 2017 by phpsane Quote Link to comment Share on other sites More sharing options...
requinix Posted September 5, 2017 Share Posted September 5, 2017 You cannot simply break a sentence apart and try to analyze individual words. That is not how the English language works. "element in any array" "??? in any array" What are your guesses as to what that ??? could possibly mean? Take your knowledge of the word "in" (something I hope you have) and use critical thinking skills (another thing I hope you have) to decide. Quote Link to comment Share on other sites More sharing options...
phpsane Posted September 5, 2017 Author Share Posted September 5, 2017 (edited) You cannot simply break a sentence apart and try to analyze individual words. That is not how the English language works. "element in any array" "??? in any array" What are your guesses as to what that ??? could possibly mean? Take your knowledge of the word "in" (something I hope you have) and use critical thinking skills (another thing I hope you have) to decide. Well. If you are talking about what is "inside the array" then I see this ... In this array: $a[0] = 1; I see "0" inside the array. And in this array: $a[1] = 3; I see "1" inside the array. And they 2 represent the array numbers. So, the "element" here is the "array numbers" ? And the count is supposed to count how many array numbers exist ? I can see 3 arrays and 3 array numbers and 3 array values. The tutorial site mentions the Count function yielding "3". That could mean anything. 3 possibilities. Like: 1). 3 arrays in number; Or; 2). 3 labels in the 3 arrays; Or 3). 3 values in all the arrays in total. No. I'm at a loss here with this tutorial and it's useless example: https://www.tutorialspoint.com/php/php_function_count.htm Now, let's try another tutorial site. (Look how much effort I make to understand something!). https://www.tutorialrepublic.com/faq/how-to-count-all-elements-in-an-array-in-php.php Now, that link mentions this: "You can use the PHP count() or sizeof() function to get the number of elements or values in an array". Again, this site is also not clear what an "element" is.However, that, erases the final possibility mentioned above. That leaves us with: 1). 3 arrays in number; Or; 2). 3 labels in the 3 arrays. I'll go for the 2) since you mention to concentrate on "in". If I'm wrong, then what is the answer ? Edited September 5, 2017 by phpsane Quote Link to comment Share on other sites More sharing options...
ginerjm Posted September 5, 2017 Share Posted September 5, 2017 Again - if you read the manual you might learn stuff. An element of an array is just that. It is an element. Much like the periodic table of elements. Elements are things. Things that get used in many places. In a computer language (not just PHP) an array element is just one of the many elements that comprise that array. Kind of like a shopping list - each one is an element, although the ordinary shopper doesn't call them that, but that is what they are. Or like the many, many posts you have made here. Each one is an element although they too are never called that. So when talking about arrays the name 'element' IS always used to identify a single piece of that array. Don't forget that multi-dimensional arrays (read about them) might contain elements that themselves are arrays. Think about that for awhile before you start a new post. 1 Quote Link to comment Share on other sites More sharing options...
requinix Posted September 5, 2017 Share Posted September 5, 2017 Well. If you are talking about what is "inside the array" then I see this ... In this array: $a[0] = 1; I see "0" inside the array. And in this array: $a[1] = 3; I see "1" inside the array. But what about 1 and 3? Aren't they in the array too? 0 and 1 are keys, 1 and 3 are values. "Element" means an array value. And they 2 represent the array numbers. So, the "element" here is the "array numbers" ?An "array number" is not a thing in PHP. Don't try to invent new terminology - you'll confuse us and yourself. Read And the count is supposed to count how many array numbers exist ?It tells you how many elements are in the array. I can see 3 arrays and 3 array numbers and 3 array values.There is only one array. It is $a. The tutorial site mentions the Count function yielding "3". That could mean anything. 3 possibilities. Read That leaves us with: 1). 3 arrays in number; Or; 2). 3 labels in the 3 arrays. Same difference. Every key in an array has a value, and every value in an array has a key. The number of elements and the number of "labels", as you called it (again, don't invent terminology), is the same. Quote Link to comment Share on other sites More sharing options...
phpsane Posted September 6, 2017 Author Share Posted September 6, 2017 Again - if you read the manual you might learn stuff. An element of an array is just that. It is an element. Much like the periodic table of elements. Elements are things. Things that get used in many places. In a computer language (not just PHP) an array element is just one of the many elements that comprise that array. Kind of like a shopping list - each one is an element, although the ordinary shopper doesn't call them that, but that is what they are. Or like the many, many posts you have made here. Each one is an element although they too are never called that. So when talking about arrays the name 'element' IS always used to identify a single piece of that array. Don't forget that multi-dimensional arrays (read about them) might contain elements that themselves are arrays. Think about that for awhile before you start a new post. Thanks for pointing out the multi dimensional arrays. Will check it out. Not sure if I read about them few mnths back when I firs read on Arrays. Before I opened this thread. If asked about an element in an Array, I would have said both the key and the value are 2 different elements in an Array. But both are elements of the Array. In other words, when you're talking about elements in an Array then you're talking about the parts that make-up the Array. Key & Value. I opened this thread to find-out in general what is meant by "element" in php. Thanks for your reply. Quote Link to comment Share on other sites More sharing options...
phpsane Posted September 6, 2017 Author Share Posted September 6, 2017 But what about 1 and 3? Aren't they in the array too? 0 and 1 are keys, 1 and 3 are values. "Element" means an array value. An "array number" is not a thing in PHP. Don't try to invent new terminology - you'll confuse us and yourself. Read It tells you how many elements are in the array. There is only one array. It is $a. Read Same difference. Every key in an array has a value, and every value in an array has a key. The number of elements and the number of "labels", as you called it (again, don't invent terminology), is the same. When I said "Array number" or "Array label", then yes, I meant the "key". I had forgotten the Array terminologies as I read on Arrays the firs time over a yr ago and the 2nd time quarter yr ago. You say "element" means an "array value". I guess you mean the element in an array is the array value. If that is what you are saying then it seems I was wrong to assume that the Array Key is also an Array element. You suggested I read the php manual on the Count function that counts the elements in an Array. But you forgot I had already mentioned earlier that i was reading on the Count function when I came across the "Array element" and opened this thread. What do you mean by: "The number of elements and the number of "labels", as you called it (again, don't invent terminology), is the same." ? "The number of elements and the number of keys are the same". That is what I am interpreting that you are saying. Am I right ? Quote Link to comment Share on other sites More sharing options...
Solution requinix Posted September 7, 2017 Solution Share Posted September 7, 2017 If that is what you are saying then it seems I was wrong to assume that the Array Key is also an Array element.That's right. You suggested I read the php manual on the Count function that counts the elements in an Array. But you forgot I had already mentioned earlier that i was reading on the Count function when I came across the "Array element" and opened this thread.I was responding to the "3 could mean anything" comment. It does not mean anything. The manual specifically says the function tells you "the number of elements in array_or_countable". What do you mean by:I mean exactly what the words themselves mean. In code you could say count(array_keys($array)) == count(array_values($array))A bit of a recursive definition, admittedly. 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.