0

This might seem like an odd questions; I know its possible to slice an array, but I was thinking, if I'm calling an array externally via a $http GET (using Angular) like so:

$http.get('/url')

is it possible for me to declare how much of the array I want to retrieve first before making the request, instead of retrieving the whole thing (and therefore saving on performance). I know its possible to do something similar using PHP but wasn't sure to the extent I had in Javascript? Or can I only slice it once the array is declared fully?

5
  • 1
    only way to do that would be add paramters for $_GET in php to return however many you want and perhaps a start point. Can't cut up something that doesn't exist yet. Also can slice the response Commented Jul 21, 2015 at 0:06
  • yeah I know you can use limitTo in Angular which is fine, but I didn't know if I could do whats possible in PHP in Javascript too Commented Jul 21, 2015 at 0:09
  • can't slice an array in php that doesn't exist either...not sure what you are talking about there Commented Jul 21, 2015 at 0:10
  • well I mean when you make a call via php to retrieve the data, you could define in the request how much to retrieve (or along the lines of) thats what I overheard from a developer who codes in PHP (which I dont...) Commented Jul 21, 2015 at 0:12
  • right but that's a database query you are referring to. So basically php needs to be told what you want so it can make appropriate query in order to send back what you ordered from the client Commented Jul 21, 2015 at 0:15

1 Answer 1

1

The only way to retrieve part of the array is for the server that you are requesting the data from to support that capability. You cannot do that entirely from the client unless the server has that capability.

The usual way that this would be done would be to add query parameters to the URL that specify how much of the data you want and for the server to look at those query parameters and to send only those pieces of the data.

For example:

$http.get('/url?start=0&end=20');

Arrays can only be sliced once they exist and have some data in them so I'm not sure what that part of the question was trying to ask about. Either the client or the server could slice the result array once they had built the initial array.

Sign up to request clarification or add additional context in comments.

1 Comment

yeah right, ok that makes sense then so would be something I'd have to integrate via the API. Thanks for the clarification

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.