Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ArrayDataSource: Use current() instead of zero index of array #16

Open
pawelkmpt opened this issue Dec 7, 2018 · 2 comments
Open

ArrayDataSource: Use current() instead of zero index of array #16

pawelkmpt opened this issue Dec 7, 2018 · 2 comments

Comments

@pawelkmpt
Copy link

I encountered following issue PHP Notice: Undefined offset: 0 in .../koolphp/koolreport/src/datasources/ArrayDataSource.php on line 111 when used associative array with keys different than integers. As far as I can see, first item of array is used to detect columns type:

foreach($data[0] as $key=>$value)
{
    $metaData["columns"][$key]=array(
        "type"=>$this->guessType($value),
    );
}

I think you could use current($data) function instead of $data[0] so you get first element regardless the key name.

@lkraav
Copy link

lkraav commented Dec 7, 2018

I agree, this makes sense, since doesnt seem to have any side-effects:

The current() function simply returns the value of the array element that's currently being pointed to by the internal pointer. It does not move the pointer in any way.

@pawelkmpt what's the secific use case for us? Why are non-integer keys better?

@koolphp
Copy link
Owner

koolphp commented Dec 9, 2018

I see, may be you following command to convert the array to using numeric keys before inserting to ArrayDataSource

$data = array_values($data);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants