help_me_with_php Posted December 21, 2012 Share Posted December 21, 2012 Sorry for the stupid question folks, but here's some code of mine I'm testing with: function test_getIndex_Of_Array() { $temp = array(); for ($i = 1; $i < 11; $i++) { $temp[$i - 1] = $i; } $count = sizeof($temp); for ($i = 0; $i < $count; $i++) { echo $i . ' ' . $temp[$i] . '<br>'; } } ////////////////////////////////////////////////////////////////////////////////// function test_ArraySum() { $temp = array(); for ($i = 1; $i < 11; $i++) { $temp[$i - 1] = $i; } $sum = array_sum($temp); echo $sum; } the 2 functions are called *in order* from a separate <php> script above that. that script just has the calls in it. I'm getting the echo from the 1st but nothing for the second. What rule about PHP am I missing here? There really needs to be a place on the web where rules about any IDE should be listed in the forms of enumerations so learning like this doesn't have to take place. After all, coding is nothing more than a bunch of rules... thanks guys. Quote Link to comment https://forums.phpfreaks.com/topic/272255-array_sum-returns-nothing/ Share on other sites More sharing options...
kicken Posted December 21, 2012 Share Posted December 21, 2012 Well, for one the code you've posted is not even valid PHP code. You're missing several closing brackets ( } ). Rather than echo, use var_dump for testing so you can get a better idea of what information is contained within a variable. For instance if the variable contained false or null then echo would show you nothing, var_dump would show you which. Copy and paste your actual code here if you want help. Quote Link to comment https://forums.phpfreaks.com/topic/272255-array_sum-returns-nothing/#findComment-1400780 Share on other sites More sharing options...
SofWare Posted December 21, 2012 Share Posted December 21, 2012 You might have solved his problem - the reason why his code wasn't working is that his brackets were in the wrong place. A php file containing only the following should work: <?php $temp = array(); for ($i = 1; $i < 11; $i++) { $temp[$i - 1] = $i; } $sum = array_sum($temp); echo $sum; ?> Quote Link to comment https://forums.phpfreaks.com/topic/272255-array_sum-returns-nothing/#findComment-1400794 Share on other sites More sharing options...
requinix Posted December 21, 2012 Share Posted December 21, 2012 Well, for one the code you've posted is not even valid PHP code. You're missing several closing brackets ( } ). You mean like the three that are indented way off to the side? Code works for me. I get 0 1<br>1 2<br>2 3<br>3 4<br>4 5<br>5 6<br>6 7<br>7 8<br>8 9<br>9 10<br>55 Quote Link to comment https://forums.phpfreaks.com/topic/272255-array_sum-returns-nothing/#findComment-1400799 Share on other sites More sharing options...
help_me_with_php Posted December 21, 2012 Author Share Posted December 21, 2012 (edited) You mean like the three that are indented way off to the side? Code works for me. I get 0 1<br>1 2<br>2 3<br>3 4<br>4 5<br>5 6<br>6 7<br>7 8<br>8 9<br>9 10<br>55 You are right, req. The others may not be. I don't understand brackets in the wrong place. I don't see it. I only post code that isn't obvious (no PHP tags were posted, that's obvious). Copy from Dreamweaver was just not congruent. Meta was off. Big deal. both code blocks works for you, req?? I only get echos for the first block. nothing is printed for the second. wonder what it is....ideas? I will try each block by themselves later on. Sofware contends that the 2nd block alone will run. I'll get back to you on that. Edited December 21, 2012 by help_me_with_php Quote Link to comment https://forums.phpfreaks.com/topic/272255-array_sum-returns-nothing/#findComment-1400816 Share on other sites More sharing options...
Barand Posted December 21, 2012 Share Posted December 21, 2012 My results also as requinix test_getIndex_Of_Array() // --> 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 test_ArraySum(); // --> 55 Quote Link to comment https://forums.phpfreaks.com/topic/272255-array_sum-returns-nothing/#findComment-1400819 Share on other sites More sharing options...
help_me_with_php Posted December 22, 2012 Author Share Posted December 22, 2012 (edited) all, this function: function test_ArraySum() { $temp = array(); for ($i = 1; $i < 11; $i++) { $temp[$i - 1] = $i; } $sum = array_sum($temp); echo $sum; } does NOT return anything for me still. but, I forgot to mention that this is testing on IIS 7.0 with PHP 5.3 I NEVER ever test non-MS stuff on MS-based machines for obvious reasons. Could this be it? This is the first time, literally, that I've never had a PHP function not work on a Microsoft IIS platform, if that really is the problem. I wouldn't doubt it, considering MS's terrible products. I realize that testing PHP on IIS is not wise and I wouldn't do it if I had an Apache option. But I don't for this run. Sorry. thoughts? that's all I can assume. nothing else makes sense. all options exhausted. thanks guys. Edited December 22, 2012 by help_me_with_php Quote Link to comment https://forums.phpfreaks.com/topic/272255-array_sum-returns-nothing/#findComment-1400835 Share on other sites More sharing options...
requinix Posted December 22, 2012 Share Posted December 22, 2012 (edited) Please don't troll us. <html> <?php error_reporting(-1); ini_set("display_errors", true); ?> <body> <h1>Today is <?php echo date("Y-m-d"); ?></h1> <p><input type="button" value="<?php echo 'This is a button'; ?>" /></p> <pre> <?php function test_getIndex_Of_Array() { $temp = array(); for ($i = 1; $i < 11; $i++) { $temp[$i - 1] = $i; } $count = sizeof($temp); for ($i = 0; $i < $count; $i++) { echo $i . ' ' . $temp[$i] . '<br>'; } } ////////////////////////////////////////////////////////////////////////////////// function test_ArraySum() { $temp = array(); for ($i = 1; $i < 11; $i++) { $temp[$i - 1] = $i; } $sum = array_sum($temp); echo $sum; } test_getIndex_Of_Array(); ?> </pre> <p><?php echo bin2hex(basename(__FILE__)); ?></p> </body> </html> What does that output? Edited December 22, 2012 by requinix Quote Link to comment https://forums.phpfreaks.com/topic/272255-array_sum-returns-nothing/#findComment-1400837 Share on other sites More sharing options...
Barand Posted December 22, 2012 Share Posted December 22, 2012 For the record, I do all my development on IIS with Windows 7.0 and the code ran just fine, as stated. Quote Link to comment https://forums.phpfreaks.com/topic/272255-array_sum-returns-nothing/#findComment-1400841 Share on other sites More sharing options...
help_me_with_php Posted December 22, 2012 Author Share Posted December 22, 2012 Please don't troll us. Are you talking to me? I'm not a troll. I can't even remember what that is or what trolls do. Like a spammer, right? Anyway,j I'm switching operating systems, so I'll let you know what the hex output looks like when I can test it. I will be a few hours if not more. thanks. Quote Link to comment https://forums.phpfreaks.com/topic/272255-array_sum-returns-nothing/#findComment-1400842 Share on other sites More sharing options...
help_me_with_php Posted December 24, 2012 Author Share Posted December 24, 2012 req, here's the output of your code (without the obvious date echo): 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 74657374322e706870 the 2nd function still didn't echo. why did you want the hex dump? Quote Link to comment https://forums.phpfreaks.com/topic/272255-array_sum-returns-nothing/#findComment-1401133 Share on other sites More sharing options...
Barand Posted December 24, 2012 Share Posted December 24, 2012 I cannot see a call to the second function in that code Quote Link to comment https://forums.phpfreaks.com/topic/272255-array_sum-returns-nothing/#findComment-1401156 Share on other sites More sharing options...
help_me_with_php Posted December 24, 2012 Author Share Posted December 24, 2012 I cannot see a call to the second function in that code you are right. man...sorry! Here's the output, and it now returns the sum. However, I'm not sure if this is relevant but my space on this shared server has now switched from Windows to Linux. I sure hope that doesn't matter, but it's possible. Isn't it? thanks. new result: 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 55 74657374322e706870 Quote Link to comment https://forums.phpfreaks.com/topic/272255-array_sum-returns-nothing/#findComment-1401171 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.