Tell me more ×
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.

i do have two dimentional array of data in php.

I do want to add another column with constant to that array for passing tabular data to next program.

i am iterating and adding manually. What can be alternate code?

my code:

            if( is_array( $arrSource )){
                foreach( $arrSource as &$dataRow){
                    foreach( $arrColumn as $k=>$v)
                        $dataRow[$k] = $v;
                }                
                unset( $dataRow );
            }
share|improve this question

1 Answer

up vote 1 down vote accepted

I see nothing wrong with what you already have. Assuming of course that you meant to append identical data to each $arrSource element. You are already doing the shorthand by using the reference operator. The only other way would be to write it all out manually, which would be pointless, unless you are looking for more novice readable code. I would hesitate to add, however, that unset should be called tithin the first foreach loop. Though I could not confirm 100% because I don't use the reference operator to know its quirks :)

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.