473,396 Members | 1,738 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Notice: Undefined offset: 49

1
Hi, I found the code here, it's excately what i am looking for, ie8 give this error "Notice: Undefined offset: 49 in.." which is this line "if ($num_of_chars[49]==$required)", i'm a newbie, i don't know how to overcome this error, so can someone please help me out?
thanks,
Expand|Select|Wrap|Line Numbers
  1. $string = "one two three";
  2. $word_array = explode(" ",$string);
  3. for ($i=count($word_array); $i>=1; $i--)
  4. {
  5. $word = $i == 1 ? " word" : " words";
  6. echo "Strings containing combination of ".$i.$word.":<br>";
  7.  
  8. $flags = array();
  9. $combination_flags = get_combination_flags(count($word_array), $i);
  10. $flags_groups = explode(",",$combination_flags);
  11. foreach ($flags_groups as $val)
  12. {
  13. $temp = chunk_split($val,1,".");
  14. array_push($flags, explode(".", substr($temp,0,(strlen($temp)-1))));
  15. }
  16. for ($j=0; $j<count($flags); $j++)
  17. {
  18. $new_string = "";
  19. for ($k=0; $k<count($word_array); $k++)
  20. $new_string .= $flags[$j][$k] ? " ".$word_array[$k] : "";
  21. trim ($new_string);
  22. echo $new_string."<br>";
  23. }
  24. echo "<br>";
  25. }
  26.  
  27. function get_combination_flags($total, $required)
  28. {
  29. $flag_array = array();
  30. $bin = "";
  31. for ($i=0; $i<$total; $i++)
  32. $bin .= "1";
  33. $dec = bindec($bin);
  34. for ($i=0; $i<=$dec; $i++)
  35. {
  36. $num_of_chars = count_chars(decbin($i), 1);
  37. if ($num_of_chars[49]==$required)
  38. {
  39. $temp = decbin($i);
  40. $length = strlen($temp);
  41. $pre = "";
  42. if ($length<$total) for ($j=$length; $j<$total; $j++) $pre .= "0";
  43. $temp = $pre.$temp;
  44. array_push($flag_array,$temp);
  45. }
  46. }
  47. return implode(",",$flag_array);
  48. }
  49. ?>
  50.  
Jul 3 '10 #1

✓ answered by zorgi

All that means is that your error_reporting in your php.ini file is set to report notices. There is two ways around this problem. First one is to set your error_reporting so it doesn't report notices:

error_reporting = E_ALL & ~E_NOTICE

that way you turn off all the notices.

OR

You can use extra condition in your if statement:

Expand|Select|Wrap|Line Numbers
  1. if ((isset($num_of_chars[49]))&&($num_of_chars[49] == $required))
  2.  

1 5106
zorgi
431 Expert 256MB
All that means is that your error_reporting in your php.ini file is set to report notices. There is two ways around this problem. First one is to set your error_reporting so it doesn't report notices:

error_reporting = E_ALL & ~E_NOTICE

that way you turn off all the notices.

OR

You can use extra condition in your if statement:

Expand|Select|Wrap|Line Numbers
  1. if ((isset($num_of_chars[49]))&&($num_of_chars[49] == $required))
  2.  
Jul 3 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: lawrence | last post by:
I just switched error_reporting to ALL so I could debug my site. I got a huge page full of errors. One of the most common was that in my arrays I'm using undefined offsets and indexes. These still...
2
by: Steven | last post by:
Hi All, I am moving some php code from a Linux machine to a Windows 2000 machine with the code belowe I get the following error : Notice: Undefined offset: 1 in c:\inetpub\wwwroot\test.php on...
1
by: google | last post by:
Hello, I'm having major problems trying to get my head round this problem. I'm trying to generate an error free script, however, I still cannot sort out this loop. I get a "Notice:...
4
by: Richard Lawrence | last post by:
Hi there, I'm having a problem with PHP which I'm not sure how to best solve. Here is the code: $fp = fopen("comments.txt", "r"); while(!feof($fp)) { $line = fgets($fp, 1024); list($key,...
6
by: nicy12 | last post by:
Hi! my name is Peter. iam working on the php platform. while trying to run and compile a program i get the undefined offset error iam nto much familiar with this error . Please help me . Thanks in...
3
by: number1yan | last post by:
Can anyone help me, i am creating a website and am using a php script that recomends the website to other people. I keep getting the same error and can not work out why. The error is: Notice:...
9
by: simple12 | last post by:
Hello I have a script which have the facility of entering any code to some part of a webpage. I have some problems with it. When i put some code in the script then their is no error shown. When i...
2
by: neridaj | last post by:
Hello, I'm trying to figure out how to get rid of these errors: Notice: Undefined offset: 1 in output_fns.php on line 315 Notice: getimagesize() : Read error! in output_fns.php on line 315...
6
by: raydiamond4u | last post by:
Hello. My name is Raymond. My code is generating the following error: Notice: Undefined offset: 2 in C:\wamp\www\imagegallery\supportfile\include\config.php on line 25 How do i correct the error?...
3
by: razvanel442 | last post by:
Hi all i am new here! I take a look on forum but i don't found a the answer for my problem ok this is my problem: Line47:$user = $_GET; Line48:$pass = $_GET; Line49:$char = $_GET;
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.