1

Can someone tell me how to create an array $custom_interval of key value pairs of days and hours:

custom_interval[[Mon][0 1 2 3 4 5 6 7]]
custom_interval[[Tue][0 1 2 3 4 5 6 7]] 

So that in PHP, I should be able to say

$hours = $custom_interval[$day];

The code that I have written gives me

[object Object]

This is the code:

//create a 2 dimentional array of days and time intervals and assign it to hidden input form element.
        for(var i=0; i<uniquedayArray.length; i++) {
                innerArray.push(uniquedayArray[i]);
                for(j=0;j<timeArray.length; j++){
                  outerArray[innerArray] = timeArray[j];
                }
        }
        alert(outerArray);

Can someone tell me what am I doing wrong? Thanks

4
  • 2
    In JavaScript arrays are object. you can try console.log(outerArray); instead of alert() Commented Aug 7, 2012 at 22:50
  • This needs basic debugging first. Make use of console.log and you should be able to find out more. Commented Aug 7, 2012 at 23:00
  • Thanks for quick response. I printed out in console log as you said, Commented Aug 7, 2012 at 23:05
  • I have selected Wed and thu as 2 days and my selected days are 0 1 2 3 4 5 6 . But I am only getting the last value.Object { wed="6" , wed,thu="6"} . Where as I was expecting Object{ wed = 0 1 2 3 4 5 6 ,thu =0 1 2 3 4 5 6} . Commented Aug 7, 2012 at 23:07

1 Answer 1

0

Have you tried looking at Javascript objects?

You could do something like:

var data = {
"monday" : [1,2,3,4,5,6,7],
"tuesday" : [1,2,3,4,5,6,7]
}

The you'd access information by saying data.monday[4]. The link introduces a method for dynamically creating these kinds of objects.

1
  • My outerArray is a javascript object : var outerArray ={}; var innerArray =[]; Commented Aug 7, 2012 at 23:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.